jquery count :visible 在 IE7 中不起作用
我使用 jQuery 创建了一个工具,该工具将根据是否选择某些复选框来显示某些表行。例如,我试图让文本显示“需要 3 张海报”。我正在使用下面的代码。在 IE7 中,它被破坏了,而不是显示 < 的数量。 tr class="隐藏"> 可见,它仅显示可见的总数。 tr 类=“隐藏”>。这段代码有什么问题吗?
$(".hidden").hide();
function countChecked() {
var n = $("tr.hidden:visible").length;
$("#numberrequired").text(n + (n <= 1 ? " Poster" : " Posters") + (n <= 1 ? "is" : " are") + " required:");
//Error message if no checkboxes are selected
if ($('input:checkbox:checked').length < 1) {
$("#numberrequired").html("<span class='required_msg'>Please select at least one checkbox.</span>");
$('#results0').hide();
//boxes[0].focus();
return false;
}
}
<h2 id="numberrequired"></h2>
以下是几行的示例:
<tr id="results1" class="hidden">
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
</tr>
<tr id="results2" class="hidden">
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
</tr>
<tr id="results3" class="hidden">
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
</tr>
I have created a tool using jQuery that will show certain table rows depending on if certain checkboxes are selected. I am trying to have text that will display "3 Posters are required" for example. I am using the code below. In IE7 it is broken and instead of showing the number of < tr class="hidden"> that are visible, it is just showing the total number of < tr class="hidden">. Is there anything wrong with this code?
$(".hidden").hide();
function countChecked() {
var n = $("tr.hidden:visible").length;
$("#numberrequired").text(n + (n <= 1 ? " Poster" : " Posters") + (n <= 1 ? "is" : " are") + " required:");
//Error message if no checkboxes are selected
if ($('input:checkbox:checked').length < 1) {
$("#numberrequired").html("<span class='required_msg'>Please select at least one checkbox.</span>");
$('#results0').hide();
//boxes[0].focus();
return false;
}
}
<h2 id="numberrequired"></h2>
Here is an example of a couple of rows:
<tr id="results1" class="hidden">
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
</tr>
<tr id="results2" class="hidden">
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
</tr>
<tr id="results3" class="hidden">
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
</tr>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是一个老错误,已经修复了大约 2 年。您可以升级您的 jquery 版本或将选择器更改为:
这是我发现人们声称可行的解决方法。
(未测试,因为我没有IE7)
This appears to be an old bug which has been fixed for about 2 years. You could upgrade your version of jquery or change your selector to this:
This is the workaround which I found people claiming would work.
(untested as I do not have IE7)