jQuery 功能同步(仅适用于警报)
这里我构造了一个数组:
var optionTexts = [];
$('#stripeMeSubSubCat tr').each(function(){
if ($(this).find('input:checkbox.subsubcat_chkclass:not(:checked)').length == 0)
{
subsubrow_cat_id_no = parseInt($(this).closest("tr").attr("id"));
optionTexts.push(parseInt(subsubrow_cat_id_no));
};
});
下面的代码仅在启用警报时才有效。我读到这可能是由于同步问题造成的。下面的代码有解决办法吗?谢谢。
$('#stripeMeSubSubCat tr').each(function(){
myindex = parseInt($.trim($(this).closest("tr").attr("id")));
if (jQuery.inArray(myindex, optionTexts) == -1) {
var equal="FALSE";
}else{
var equal="TRUE";
$("#stripeMeSubSubCat tr[id='" + myindex + "'] input").attr('checked', true);
};
//alert(equal);
});
Here I construct an array:
var optionTexts = [];
$('#stripeMeSubSubCat tr').each(function(){
if ($(this).find('input:checkbox.subsubcat_chkclass:not(:checked)').length == 0)
{
subsubrow_cat_id_no = parseInt($(this).closest("tr").attr("id"));
optionTexts.push(parseInt(subsubrow_cat_id_no));
};
});
The code below only works whenever the alert is enabled. I have read that this might be due to a synchronization issue. Is there a solution towards the code below? Thank you.
$('#stripeMeSubSubCat tr').each(function(){
myindex = parseInt($.trim($(this).closest("tr").attr("id")));
if (jQuery.inArray(myindex, optionTexts) == -1) {
var equal="FALSE";
}else{
var equal="TRUE";
$("#stripeMeSubSubCat tr[id='" + myindex + "'] input").attr('checked', true);
};
//alert(equal);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“仅在启用警报时才有效”是什么意思?您需要描述这两种情况下行为的差异。
您的代码没有异步调用,因此不应该存在同步问题。但是,您似乎使用整数作为 DOM 元素 id。这是不允许的。
What do you mean by "only works whenever the alert is enabled"? You need to describe the difference in behavior in both cases.
Your code has no asynchronous calls, so there shouldn't be synchronization issue. However, you seem to be using an integer as a DOM element id. This isn't allowed.
您可能需要等待 DOM 加载。尝试将此代码包装在:
You probably need to wait for the DOM to load. Try wrapping this code in: