我使用此代碼,效果很好。現在我只需要更改輸入名稱,input1,input 2等等。循環中的問題
<script type="text/javascript">
$(document).ready(function() {
$("#input1 > select.profissao").live('change', function(){
$.ajax({
type: "POST",
data: "data=" + $(this).val(),
url: "drop1.php",
success: function(html) {
$("#input1 > select.estatistica").html(html);
}
});
});
});
</script>
爲什麼這個版本不起作用?我已經檢查了lint中的代碼,並且沒有檢測到任何錯誤。 基本上,如果我複製上面的代碼,並將input1更改爲input2,效果很好,但我的目標是減少冗餘。
<script type="text/javascript">
$(document).ready(function() {
for (i=1; i<3; i++) {
$("#input"+i+" > select.profissao").live('change', function(){
$.ajax({
type: "POST",
data: "data=" + $(this).val(),
url: "drop1.php",
success: function(html) {
$("#input"+i+" > select.estatistica").html(html);
}
});
});
}
});
</script>
編輯:輸出是類似的東西<option value=2>Artes</option><option value=1>Humanidades</option>
但這不是添加到HTML
與環路我的下拉簡單停止工作
你可以發佈你的HTML,我有一種感覺,你可以處理這個沒有每個輸入的事件處理程序。 – Ben