简体   繁体   English

jQuery选择器属性范围

[英]jQuery selector attribute range

I have a table with some rows and cols, each of them hast an attribute: 我有一个带有一些行和列的表,它们每个都有一个属性:

<tr attr-y="1"><td attr-x="1">...</td><td attr-x="2">...</td>...</tr>
<tr attr-y="2"><td attr-x="1">...</td><td attr-x="2">...</td>...</tr>
....

Now I want to edit some of these cells and tried to select them by a range, eg. 现在,我想编辑其中一些单元格,并尝试按一定范围选择它们,例如。 ( attr-y between 3 and 5, attr-x = 4 ) attr-y在3到5之间, attr-x = 4

$('#mytable tr[attr-y>3][attr-y<5] td[attr-x=4]')

But that gives me all cells in that column. 但这给了我该列中的所有单元格。

Can I select the cells direct (with selector statement)? 我可以直接选择单元格(使用选择器语句)吗?

You can use .filter() to perform more complex query: 您可以使用.filter()执行更复杂的查询:

$('#mytable td').filter(function() {
    return ($(this).parent().attr('attr-y') > 3 && $(this).parent().attr('attr-y') < 5)
        && ($(this).attr('attr-x') == 4)
})
.css('background-color', 'aqua');

Example: http://jsfiddle.net/8wH4M/1/ 示例: http//jsfiddle.net/8wH4M/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM