我有一类文本框,并尝试将onChange事件附加到类中。下面的代码有效,我从firefox中获取calData的输出,但在Chrome上不起作用
enter code here
<ul id="week_list">
<li id="34">
Week 1 - <input class="test_class" type="number" id="week_34" name="week[]">
</li>
<li id="35">
Week 2 - <input class="test_class" type="number" id="week_35" name="week[]">
</li>
</ul>
//Javascript
var Test =
{
init: function(config) {
this.bindEvents();
},
bindEvents: function() {
this.config.clTest.on('change',this.calData);
},
calData: function(){
console.log("calculating");
},
};
Test.init({
clTest: $('.test_class'),
});
答案 0 :(得分:1)
你需要改变你的js是这样的
var Test =
{
config:null,
init: function(c) {
config = c;
console.log(config);
this.bindEvents();
},
bindEvents: function() {
config.clTest.on('change',this.calData);
},
calData: function(){
console.log("calculating");
}
};
Test.init({
clTest: $('.test_class'),
});
忘了加入demo