【问题标题】:The events go out after ajax updateajax更新后事件消失
【发布时间】:2016-05-09 16:42:47
【问题描述】:

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

感谢之前

【问题讨论】:

标签: jquery input checkbox


【解决方案1】:

这就是 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,然后使用 ajax 返回的 html 更新 #regionLocalList div:

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

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

【讨论】:

猜你喜欢
  • 2015-05-02
  • 2019-02-11
  • 1970-01-01
  • 2014-04-06
  • 2010-09-23
  • 2014-06-02
  • 1970-01-01
  • 2019-06-14
相关资源
最近更新 更多