我在执行ajax调用后构造了2个复选框。当我尝试引用它们的id来执行.change()事件时,事件不会触发。有任何想法吗?这里是我的代码:Jquery .change()事件问题
Ajax调用:
$.ajax({
url:"../includes/MC.Admin.ajax.php",
type: "POST",
data: empupdatedata,
success: function(empupdate) {
var empupdateJson = $.parseJSON(empupdate);
$("#empupdateinfo_tbl").html(empupdateJson.updateempinfo);
$("#empemploymentupdateinfo_tbl").html(empupdateJson.updateempemploymentinfo);
$('#employee-update').bPopup({
modalClose: false
});
}
});
这是构建文本框:
if($rm5->isbonus == 1 && $rm5->isallowance == 0)
{
$updateemployeeemploymentinfo .= "<tr><td class = 'tbl_data'>
Additional Payment</td><td>Bonus <input type = 'checkbox'
name = 'isbonus' id = 'uisbonus'> Allowance <input type = 'checkbox'
name = 'isallowanece' id = 'uisallowance'></td></tr><tr></tr>";
}
我想用这两个复选框的ID的触发更改事件使用以下代码:
$("#uisbonus").change(function(){
if($(this).attr("checked"))
{
$('#uamountcon').append("<td id = 'uamountcon'><input type = 'text' id = 'uamount ></td>")
}
else
{
$('#uamountcon').html();
}
});
$("#uisallowance").change(function(){
if($(this).attr("checked"))
{
$('#uamountcon').append("<td id = 'uamountcon'><input type = 'text' id = 'uamount ></td>")
}
else
{
$('#uamountcon').html();
}
});//I placed this code insidethe $(document).ready(function() { });
更改事件的位置是否错误?我应该在哪里举办活动?或者是什么问题?谢谢!
你在控制台中的错误?你预计什么时候开火? – bPratik 2012-07-26 15:57:25
将元素添加到页面(在ajax成功范围内)后直接将更改事件绑定移动,或者使用'.delegate'或'.on'与委托语法绑定事件。 – 2012-07-26 15:57:34
您的问题缺少有关_when_您尝试绑定处理程序的信息。它可能是你实际插入元素之前绑定的。您可能想看看jquerys live()方法或其后继者。 – arkascha 2012-07-26 15:57:53