2011-05-19 68 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.'); 
      }); 
     }); 
相關問題