微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果这被检查,jquery在IE 9中不起作用?

这里使用 jquery复选框单击功能,如果我单击IE 9中的复选框if($(this).is(‘:checked’))它不会抛出警报消息..但它在IE 10中工作,Firefox和铬
if (isChildAvail == "true") 
{
    $(this).change(function() {
            if ($(this).is(':checked')) {
            alert("test");
            $(this).parent().parent().append('<div id="divedit" class="editdiv"><p id="p_childlabel" class="childlabel">Children : ' + ChilAvailCount + '   </P><a class="childlabeledit">Edit</a></div>');
            $('.editdiv a').click(function() {
            $(this).parent().parent().append($("#divchildcontrol"));
            EditForPullups();
         });
         }
  }

有什么建议??

编辑:

$(this).change(function() {

问题是改变功能而不是这个(如果($(this).is(‘:checked’))

EDIT(2):

var strCheck = "";
$('.consumer-communication-checkBox').each(function () {

        strCheck = $(this).parent().text();


        if (strCheck.toLowerCase().indexOf("hugg") >= 0) {

            //scenario without child
            if (isChildAvail == "false") {
                jQuery(':checkBox').change(function () {
                    if ($(this).prop('checked') === true) {
                        $(this).parent().parent().append($("#divchildcontrol"));
                        IsChildcontrolwithH = "1";
                        IsChildcontrolwithG = "0";
                        IsChildcontrolwithP = "0";
                    } else {
                        if (IsChildcontrolwithH == "1") {
                            $("#divpersonalrightheader").append($("#divchildcontrol"));
                        }
                    }
                });
            }
            //scenario with child
            else {
                if ($(this).prop('checked') === true) {
                    //Set SubscribedCode
                    SubscribedCode = "H";
                    $(this).parent().parent().append('<div id="divedit" class="editdiv"><p id="p_childlabel" class="childlabel">Children : ' + ChilAvailCount + '   </P><a class="childlabeledit">Edit</a></div>');
                    $('.editdiv a').click(function () {
                        $(this).parent().parent().append($("#divchildcontrol"));
                        EditForH();
                    });
                }

                jQuery(':checkBox').change(function () {
                    if ($(this).prop('checked') === true) {
                        $(this).parent().parent().append('<div id="divedit" class="editdiv"><p id="p_childlabel" class="childlabel">Children : ' + ChilAvailCount + '   </P><a class="childlabeledit">Edit</a></div>');
                        $('.editdiv a').click(function () {
                            $(this).parent().parent().append($("#divchildcontrol"));
                            EditForH();
                        });
                    } else {
                        $("#divedit").remove();
                        if (IsChildcontrolwithH == "1") {
                            $("#divpersonalrightheader").append($("#divchildcontrol"));
                            IsChildcontrolwithH = "0";
                            IsChildcontrolwithG = "0";
                            IsChildcontrolwithP = "0";
                        }
                    }

                });
            }
        }

编辑(3):Html内容

<div class="consumer-checkBox-wrap checked">
                <label class="consumer-communication-label checkBox" for="communication_11">
                    <input name="communication_11" class="consumer-communication-checkBox checkBox" id="communication_11"
                        type="checkBox" checked="checked" value="true"><img src="Images/PMURP_logos/hugg.jpg">
                s
                    <p>
                        Please send me communications,savings,and special offers from hugg® Communications
                    </p>
                </label>
                <input name="communication_11" type="hidden" value="false"><a href="http://www.hugg.com/email/12162011/SampleNewsletter.html"
                    target="_blank"><img src="../kcsso/images/Newsletter/hugg.jpg"></a>
</div>
 <div class="consumer-checkBox-wrap">
            <label class="consumer-communication-label checkBox" for="communication_13">
                <input name="communication_13" class="consumer-communication-checkBox checkBox" id="communication_13"
                    type="checkBox" value="true"><img src="Images/PMURP_logos/scott.jpg">

                <p>
                    Please send me communications,and special offers from scott® Communications</p>
            </label>
            <input name="communication_13" type="hidden" value="false"><a href="http://www.scott.com/email/11042011/samplenewsletter.html"
                target="_blank"><img src="../kcsso/images/Newsletter/scott.jpg"></a>
</div>

解决方法

您发布的代码最后缺少一些结束括号,我不确定您是否只是没有复制/粘贴所有代码,或者如果它丢失并且破坏了您的代码

这是您发布的内容(在整理缩进后):

if (isChildAvail == "true") {
    $(this).change(function () {
        if ($(this).is(':checked')) {
            alert("test");
            $(this).parent().parent().append('<div id="divedit" class="editdiv"><p id="p_childlabel" class="childlabel">Children : ' + ChilAvailCount + '   </P><a class="childlabeledit">Edit</a></div>');
            $('.editdiv a').click(function () {
                $(this).parent().parent().append($("#divchildcontrol"));
                EditForPullups();
            });
        }
    }

它缺少更改事件处理程序的结束);以及if块的结束}:

if (isChildAvail == "true") {
    $(this).change(function () {
        if ($(this).is(':checked')) {
            alert("test");
            $(this).parent().parent().append('<div id="divedit" class="editdiv"><p id="p_childlabel" class="childlabel">Children : ' + ChilAvailCount + '   </P><a class="childlabeledit">Edit</a></div>');
            $('.editdiv a').click(function () {
                $(this).parent().parent().append($("#divchildcontrol"));
                EditForPullups();
            });
        }
    });
}

这个(简化的)示例在IE9中适用于我:
http://jsfiddle.net/rT2dT/1/

$(':checkBox').change(function () {
    if ($(this).is(':checked')) {
        alert("test");
    }
});

或者,试试吧

$(':checkBox').change(function () {
    if ($(this).prop('checked') === true) {
        alert("test");
    }
});

您使用的是哪个jQuery版本?

编辑:
跟进上面的第二次编辑:

我看到你在每个循环中附加事件处理程序

$('.consumer-communication-checkBox').each(function () {

我假设该选择器将在您页面上的各种复选框上.在每个外观里面,你都附加了更改处理程序:

$(':checkBox').change(...

此选择器将为您提供整个页面上的所有复选框,而不仅仅是范围中的复选框.在每个循环的每次迭代中,您将其中一个事件处理程序附加到页面上的每个复选框.在不知道你的HTML标记的情况下,我无法告诉你究竟发生了什么,但这就是为什么一切都按照预期在孤立的例子(如JSfiddle.net)中工作并在上下文中返回随机结果的原因.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐