【发布时间】:2010-07-09 21:27:29
【问题描述】:
我知道我可以将属性检查更改为检查,但我需要实际“单击”复选框以触发 live() (jQuery) 单击事件。我知道我也可以把它变成一个函数,但如果可能的话,这只会更简洁,代码更少。
哦,仅供参考:
$('.modal-form [name='+json[0].owners[x].name+']').click();
不起作用。它检查 em,但实际上并没有将它们“点击”到 jQuery 触发 live() 事件的位置
如果有人感兴趣,这里是 AJAX 调用:
$('.agenda-modal input[type=checkbox]:not([name="emergency-item"])').live('click',function(){
iid = $('.agenda-modal').attr('data-defaultitemid');
the_type = $(this).parent().parent().attr('id');
checked_item = $(this).val();
if($(this).attr('checked')){
if(the_type == 'the-elected-list'){
$livepreview.agenda({
action:'update',
type:'owner',
id:iid,
owner:checked_item
});
}
else if(the_type == 'the-bureau-list'){
$livepreview.agenda({
action:'update',
type:'bureau',
id:iid,
bureau:checked_item
});
}
}
else{
$livepreview.agenda({
action:'get',
type:'item',
id:iid,
callback:function(json){
if(the_type == 'the-elected-list'){
for(x in json[0].owners){
if(json[0].owners[x].name == checked_item){
$livepreview.agenda({
action:'delete',
type:'owner',
id:json[0].owners[x].item_owner_id
});
}
}
}
else if(the_type == 'the-bureau-list'){
for(x in json[0].bureaus){
if(json[0].bureaus[x].name == checked_item){
$livepreview.agenda({
action:'delete',
type:'bureau',
id:json[0].bureaus[x].item_bureau_id
});
}
}
}
}
});
}
});
【问题讨论】:
-
请举个例子。通过制作复杂的表达式,您很可能找不到正确的元素。把它调低。
-
@meder 好吧,如果它正在检查复选框,那么他正在找到正确的元素。
-
不,就像我说的那样,在上面的代码中,它点击(并检查元素)但不点击元素......有一个 AJAX 调用(在上面 1 秒内发布)当单击复选框以即时保存选择时会触发它。
-
您使用的是什么版本的 jQuery?我认为在 1.4 之前(实际上 1.4.2 是 1.4 的“固定”版本)事件冒泡有点不稳定
-
嗯,一个非常简单的测试页面表明它可以工作 - 是不是某个父元素上有一个“click”处理程序,它返回“false”?
标签: javascript jquery html forms checkbox