bal*_*569 6 checkbox jquery internet-explorer-9
这里使用jquery复选框单击功能,如果我单击IE 9中的复选框, if ($(this).is(':checked')) 它不会抛出警报消息..但它在IE 10,Firefox和Chrome中工作
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();
});
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议??
编辑:
$(this).change(function() {
Run Code Online (Sandbox Code Playgroud)
问题在于改变功能,而不是这个 if ($(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";
}
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
编辑(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, savings, 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>
Run Code Online (Sandbox Code Playgroud)
您发布的代码最后缺少一些结束括号,我不确定您是否只是没有复制/粘贴所有代码,或者如果它丢失并且破坏了您的代码:
这是您发布的内容(在整理缩进后):
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();
});
}
}
Run Code Online (Sandbox Code Playgroud)
它缺少更改事件处理程序的结束); 以及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();
});
}
});
}
Run Code Online (Sandbox Code Playgroud)
这个(简化的)示例在IE9中适用于我:http: //jsfiddle.net/rT2dT/1/
$(':checkbox').change(function () {
if ($(this).is(':checked')) {
alert("test");
}
});
Run Code Online (Sandbox Code Playgroud)
或者,试试吧
$(':checkbox').change(function () {
if ($(this).prop('checked') === true) {
alert("test");
}
});
Run Code Online (Sandbox Code Playgroud)
您使用的是哪个jQuery版本?
编辑: 跟进上面的第二次编辑:
我看到你在each循环中附加事件处理程序
$('.consumer-communication-checkbox').each(function () {
Run Code Online (Sandbox Code Playgroud)
我假设该选择器将在您页面上的各种复选框上.在这个each外观中,您可以附加更改处理程序,如下所示:
$(':checkbox').change(...
Run Code Online (Sandbox Code Playgroud)
此选择器将为您提供整个页面上的所有复选框,而不仅仅是范围中的复选框.在循环的每次迭代中,each您将其中一个事件处理程序附加到页面上的每个复选框.在不知道你的HTML标记的情况下,我无法告诉你究竟发生了什么,但这就是为什么一切都按照预期在孤立的例子(如JSFiddle.net)中工作并在上下文中返回随机结果的原因.
尝试替换$为jQuery. 也许我错了,但看起来另一个库正在覆盖$机制并导致未定义的方法调用。
更新更新:
所以这是没有按预期工作的部分:
//else {
$("#divedit").remove();
if (IsChildcontrolwithH == "1") {
$("#divpersonalrightheader").append($("#divchildcontrol"));
IsChildcontrolwithH = "0";
IsChildcontrolwithG = "0";
IsChildcontrolwithP = "0";
}
//}
Run Code Online (Sandbox Code Playgroud)
没有什么问题。
但是,如果 ID 为divpersonalrightheader 的元素或 ID 为divchildcontrol的元素此时不存在,则不会执行任何操作。当然,我假设你的IsChildcontrolwith*变量逻辑是正确的。删除这些变量可能是一个好主意,以避免处理许多类似标志的变量。如果您需要在元素周围放置一些数据,可以使用$(...).data().