简体   繁体   中英

Select value / text / number from table cell?

I am new to Jquery / JS - as I'm playing with it for the first time this week.

I have a giant html table in a cfm file. It goes something like this:

...

<td nowrap align="center"><INPUT readonly type="text" name="ttct"  SIZE="5"></td>
<td nowrap align="center"><INPUT readonly type="text" name="ttemp"  SIZE="5"></td>
<td nowrap align="center"><INPUT readonly type="text" name="ttpdp"  SIZE="5"></td>

...

The values of these cells are set elsewhere in the JS. What I want to do is select all of the cells that have a particular value (zero, in this case), and set them to null.

In a separate js file, I have a function which says:

...

$('input[name^="t"]').filter('input[name$="p"]').val('')
$('input[name^="t"]').filter('input[name$="d"]').val('')
$('input[name^="r"]').filter('input[name$="p"]').val('')
$('input[name^="r"]').filter('input[name$="d"]').val('')

...

Which selects ALL of the cells. How do I filter that to only set those which are zero to null, instead of ALL of the cells?

I've been trying a lot of things to no avail.

$('td input:text').filter(function() { return $(this).val() == 0; }).val("");

要么

$('td input:text[value="0"]').val("");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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