0

我有一类文本框并试图将 onChange 事件附加到该类。下面的代码有效,我从 calData 在 Firefox 中获得输出,但在 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'),
 });

4

1 回答 1

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'),
 });​

忘记包含演示

于 2012-07-10T21:33:34.650 回答