2010-05-08 48 views
0

我已经编写了检查/取消选中在页面的fisrt加载中运行良好的输入代码,但由于我通过ajax添加了输入,然后使用新输入重新加载输入,检查/不检查事件不再有效,我不知道有什么问题。前ajax更新后发生的事件

感谢

+0

你可以发布检查代码吗? – 2010-05-08 15:08:34

+0

最后我找到了解决方案,我们可以使用live()事件来绑定新的输入,我邀请你关注这个线程http://stackoverflow.com/questions/770308/events-not-registering-after-replacewith/ 2838259 – 2010-05-14 23:35:48

回答

0

这就是XHTML标记:

<div style="display: block;" id="regionLocalList"> 
    <div class="itemRegionCountry"> 
     <input type="checkbox" checked="checked" value="1" name="auteur[]" id="aucun"> 
     <label for="tous">no actor</label> 
    </div> 
    <div class="itemRegionCountry"> 
     <input type="checkbox" value="3" name="auteur[]" id="3"> 
     <label>others</label> 
    </div> 
    <div class="itemRegionCountry"> 
     <input type="checkbox" value="510" name="auteur[]" id="510"> 
    <label for=" Nick">Nick</label> 
    </div> 
    <div class="itemRegionCountry"> 
     <input type="checkbox" value="509" name="auteur[]" id="509"> 
     <label for="Craver">Craver</label> 
    </div> 
</div> 

这就是选择/取消jQuery代码

var othercheckboxes = $("#regionLocalList .itemRegionCountry input:not(#aucun)"); 
var aucun = $("#aucun"); 
$("#regionLocalInput").click(function(event) { 
$("#regionLocalList").toggle(); 
              }) 
$(aucun).click(function(event) { 
$(aucun).attr('checked',true); 
$(othercheckboxes).attr('checked',false); 
           }); 
$(othercheckboxes).click(function(event) { 
       if (this.checked){ 
       $(aucun).attr('checked',false); 
           } 
$(othercheckboxes).each(function (i) { 
      if ($(this).is(':checked')) { 
      $(aucun).attr('checked',false); 
      return false; 
      } 
      else 
      { 
      return $(aucun).attr('checked',true); 
      } 
    }); 
}); 

通过一个jQuery UI的对话框添加新的输入之后,我检索同样的xhtml上面有一个新的输入,之后我更新了#regionLocalList div与html返回的ajax:

$("#regionLocalList").replaceWith(html); 

新的输入出现,但事件不起作用

+0

最后我找到了解决方案,我们可以使用live()事件绑定新的输入,我邀请你关注这个线程http://stackoverflow.com/questions/770308/events-not-registering-after-replacewith/2838259 – 2010-05-14 23:35:06

相关问题