2015-07-28 151 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 ! 
});