2011-05-19 66 views
1

我知道这个问题之前被问过,但我有以下简单的代码是不是在IE/MOZILLA工作 这是一个简单的脚本,我正在尝试整理我有一个问题。 看到下面的代码选择不发射IE8的JQuery更改事件Firefox 4.0.1

<script type="text/javascript"> 
     $(document).ready(function() { 
      alert('hi'); 
     }); 

     $('.target').change(function() { 
      alert('Handler for .change() called.'); 
     }); 
    </script> 
    Index</h2> 
<p> 
<form action="/Review" method="post">  <select class="target"> 
      <option value="option1" selected="selected">Option 1</option> 
      <option value="option2">Option 2</option> 

     </select> 
+1

“在IE/Mozilla浏览器不工作”?它在任何其他浏览器中工作吗? – 2011-05-19 05:27:11

回答

1

你需要移动.change结合成的$(document).ready()或它将运行之前有在你的.target选择相匹配的DOM东西:

$(document).ready(function() { 
    alert('hi'); 
    $('.target').change(function() { 
     alert('Handler for .change() called.'); 
    }); 
}); 
0

尝试更改这样的脚本。

$(document).ready(function() { 
      alert('hi'); 
      $('.target').change(function() { 
      alert('Handler for .change() called.'); 
      }); 
     }); 
相关问题