【发布时间】:2009-12-09 10:00:07
【问题描述】:
我在 jQuery 中得到了一些令人困惑的结果,包括 attr('class') 和 hasClass()。基本上,我正在遍历表行并确定下一个可见表行是否具有某个类。
$('table#blocks tr.region').each(function () {
var next_row = $(this).nextAll('tr:visible');
console.log('This: ' + $(this).attr('class') + ' Next: ' + next_row.attr('class') + ' Next is a region: ' + next_row.hasClass('region'));
});
当我运行这个脚本时,日志显示:
这个:region region-left 下一个:region region-right 下一个是一个区域:true
这个:region region-right 下一个:region region-content 下一个是一个区域:true
这个:region region-content 下一个:draggable even shown_on_home shown_on_infozone 接下来是一个区域:true
这个:region region-header 下一个:region-message region-header-message region-empty 接下来是一个区域:true
这个:region region-footer 下一个:region-message region-footer-message region-empty 接下来是一个区域:true
This: region region--1 Next: undefined Next is a region: false
所以消息清楚地表明有些行具有类“区域”而有些没有,但它们都为 hasClass() 返回 true!
有人能解释一下吗?
谢谢:)
【问题讨论】:
-
这个玛丽亚有什么进展吗?您为什么不对给出的答案提供反馈?我的回答不适合你吗?
标签: jquery