Javascript 如何在聚合物中制造一次改变事件
我收到此消息TypeError:document.addEventListener(…)不是函数Javascript 如何在聚合物中制造一次改变事件,javascript,polymer,document-ready,Javascript,Polymer,Document Ready,我收到此消息TypeError:document.addEventListener(…)不是函数 (document.addEventListener('polymer-ready',function($){ console.log('ready') // top link $.each(decodeURI(location.pathname).split('/'), function() { $("#self").html(this+''); }); /
(document.addEventListener('polymer-ready',function($){
console.log('ready')
// top link
$.each(decodeURI(location.pathname).split('/'), function() {
$("#self").html(this+'');
});
// browser default lang
default_lang = navigator.language /* Mozilla */ || navigator.userLanguage /* IE */;
// does URL contain lang=xx ?
$.each(decodeURI(location.search.substr(1)).split('&'), function() {
var s = this.split('=');
if (s[0]=="lang") default_lang = s[1];
});
// toplevel = earth
$("#earth").click(
function(e) {
e.preventDefault();
//location.href = "http://www.geonames.org";
}
);
// entry point
geo_click($("#earth"));
}))(jQuery);
有人能告诉我这有什么问题吗?您的代码无效您正在将document.addEventListener视为一种生命,而事实并非如此。您在错误的位置执行(jQuery) 将jQuery传递到立即函数,而不是事件侦听器
(function ($) {
document.addEventListener('polymer-ready', function () {
console.log('ready')
// top link
$.each(decodeURI(location.pathname).split('/'), function () {
$("#self").html(this + '');
});
// browser default lang
var default_lang = navigator.language /* Mozilla */ || navigator.userLanguage /* IE */;
// does URL contain lang=xx ?
$.each(decodeURI(location.search.substr(1)).split('&'), function () {
var s = this.split('=');
if (s[0] == "lang") { default_lang = s[1] };
});
// toplevel = earth
$("#earth").click(
function (e) {
e.preventDefault();
//location.href = "http://www.geonames.org";
}
);
// entry point
geo_click($("#earth"));
});
})(jQuery);
问题解决了强>
function geoready(){
console.log('ready');
// top link
$.each(decodeURI(location.pathname).split('/'), function() {
$("#self").html(this+'');
});
// browser default lang
default_lang = navigator.language /* Mozilla */ || navigator.userLanguage /* IE */;
// does URL contain lang=xx ?
$.each(decodeURI(location.search.substr(1)).split('&'), function() {
var s = this.split('=');
if (s[0]=="lang") default_lang = s[1];
});
// toplevel = earth
$("#earth").click(
function(e) {
e.preventDefault();
//location.href = "http://www.geonames.org";
}
);
// entry point
geo_click($("#earth"));
}
我将其绑定到聚合物构造器中:
<script>
Polymer({
is: "geo-dropdown",
ready: geoready
});
</script>
聚合物({
是:“geo下拉列表”,
准备好了:乔治
});
那么,我该如何解决这个问题呢?虽然付出了很大的努力,但没有成功:(恐怕我们无法编写文档。addEventListener('polymer-ready',function())。。。