简体   繁体   中英

live search for a substring in a table in javascript

I have been testing this code which I found on the Internet http://jsfiddle.net/FranWahl/rFGWZ/ but what I really want to do is to search for a substring in the table row. For example if I had this table

<table>
<tr><th>Unique ID</th><th>Random ID</th></tr>
<tr><td>214215</td><td>442</td></tr>
<tr><td>1252512 ab</td><td>556</td></tr>
<tr><td>2114 </td><td>4666</td></tr>
<tr><td>3245466</td><td>334</td></tr>
<tr><td>24111</td><td>54364</td></tr>
</table>

I would like to search for "ab". Is this possible ? and with which function?

Change the following line:

if (id.indexOf(value) !== 0) {

to

if (id.indexOf(value) === -1) {

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