gpt4 book ai didi

javascript - 我可以在 javascript 函数中使用 jquery 方法、选择器吗?

转载 作者:行者123 更新时间:2023-11-28 20:26:36 24 4
gpt4 key购买 nike

HTML:

<input id="otherCheckbox2" type="checkbox" value="Accepted" style="color: Black" class="chkdisplay" onchange="javascript:othercheckbxdisplay();" /> 
<span style="color: Black">Accepted</span> <br />
<input id="otherCheckbox3" type="checkbox" value="Contracted" style="color: Black" class="chkdisplay" onchange="javascript:othercheckbxdisplay();" />
<span style="color: Black">Contracted</span> <br />
<input id="otherCheckbox4" type="checkbox" value="Pending" style="color: Black" class="chkdisplay" onchange="javascript:othercheckbxdisplay();" />
<span style="color: Black">Pending</span><br />
<input id="otherCheckbox5" type="checkbox" value="Pre-Authorized" style="color: Black" class="chkdisplay" onchange="javascript:othercheckbxdisplay();" />
<span style="color: Black">Pre-Authorized</span> <br />
<input id="otherCheckbox6" type="checkbox" value="Show Deleted" style="color: Black" class="chkdisplay" onchange="javascript:othercheckbxdisplay();" />
<span style="color: Black">Show Deleted</span> <br />
<input id="otherCheckbox7" type="checkbox" value="Treated" style="color: Black" class="chkdisplay" onchange="javascript:othercheckbxdisplay();" />
  <span style="color: Black">Treated</span> <br />

我的 javascript 函数与 jquery 但不起作用。在按钮单击上调用此函数。当我单击按钮 alert("hi"); 时,它会被触发,但不会 alert(index); 还要解释一下我的主要问题,只是我来回答这个问题

 function ShowHideDxColumn() {
alert("hi");
$(".ckhdisplay").each(function (index) {
if ($(this).is(":checked")) {
alert(index);
}
});
}

谢谢你

最佳答案

您有一个拼写错误,.ckhdisplay 应该是 .chkdisplay。因此,您的 .each 调用没有可迭代的元素,因为没有给定类的元素。

 function ShowHideDxColumn() {
alert("hi");
$(".chkdisplay").each(function (index) {
if ($(this).is(":checked")) {
alert(index);
}
});
}

您实际上并不需要每个条件,您只需选择选中的复选框即可:

$(".chkdisplay:checked").each(function(index){
console.log(this);
});

关于javascript - 我可以在 javascript 函数中使用 jquery 方法、选择器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17269744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com