jquery repeat text search and cut
How jquery search a repeat text and get row id of other repeat row.
<tr id='1'>
<td>AA</td>
</tr>
<tr id='2'>
<td>BB</td>
</tr>
<tr id='3'>
<td>AA</td>
</tr>
<tr id='4'>
<td>AA</td>
</tr>
<tr id='5'>
<td>BB</td>
</tr>
<tr id='6'>
<td>CC</td>
</tr>
<tr id='7'>
<td>BB</td>
</tr>
for exam开发者_Go百科ple I want id 3,4(for AA) 5,7(for BB) and no id for CC because is no repeat. thank you.
Something like this should work:
function repeats() {
var seen = {};
var ids = [];
jQuery("tr").each(function() {
var text = jQuery(this).find("td").text();
if(!seen[text]) {
seen[text] = 1;
}
else {
seen[text]++;
}
if(seen[text] > 1) {
ids.push(this.id);
}
});
return ids;
}
Fiddle here
Something like this...
$('tr td').each(function(){
var a = $(this).parent().attr('id');
if($(this).text() == 'AA'){
document.write(a + '<br />');
}
});
Example: http://jsfiddle.net/jasongennaro/GDEWm/1/
精彩评论