2015-07-28 174 views
-1

這裏有什麼問題, 的index.phpjQuery的事件監聽器不工作

<div id="divM"></div> 
<script src="jquery-1.9.1.min.js"></script> 
<script src="index.js"></script> 

index.js

$("#select01").change(function(){ 
    var a = $(this).val() + ".php"; 
    $("#divM").load(a); 
}); 

因此,一個頁面加載內divMselect03是裏面裝頁。

index.js

$("#select03").on("change", function(){ 
    alert ("323"); // nothing happens here ! 
}); 
+0

檢查此問題http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements –

+0

解決,非常感謝 – bonaca

回答

1

使用event-delegation

$("#divM").on("change", "#select03", function(){ 
    alert ("323"); // nothing happens here ! 
}); 
1
Try this 
$(document.body).on("change","#select03", function(){ 
    alert ("323"); // nothing happens here ! 
}); 
$("#select01").change(function(){ 
var a = $("#select01 option:selected").val() + ".php"; 
$("#divM").load(a); 
}); 
1

改變你的函數:

$(document).on("change", "#select03", function(){ 
    alert ("323"); // nothing happens here ! 
}); 
1

試試下面的代碼:

$(document).on("change", "#select03", function(){ 
    alert ("abc"); // nothing happens here ! 
});