該腳本用于使用兩個標準輸入字段對HTML表格進行排序,但是我試圖將select用作第二個輸入字段,并且我似乎無法找到一種方法來調用函數onchange來讓select specialidid id用作輸入。請幫忙。非常感謝你!這是代碼:<script src="https://code.jquery.com/jquery-1.7.1.js"></script><input type="text" id="infoid" placeholder="Contractor Name"><select id="specialtyid" onChange=" "> <option value="">Select Contractor Type:</option> <option value="Electrician">Electrician</option> <option value="HVAC">HVAC</option> <option value="Plumber">Plumber</option></select><p></p><table id="table"> <tr> <td>Jack Doe</td> <td>HVAC</td> </tr> <tr> <td>Jack Doe JR</td> <td>Plumber</td> </tr> <tr> <td>Jane Doe</td> <td>Electrician</td> </tr> <tr> <td>Rick Pro</td> <td>Plumber</td> </tr></table>$(window).load(function() { var $rows = $('#table tr'), info, specialty; $('input').keyup(function() { infovalue = $('#infoid').val().toLowerCase(), specialtyvalue = $('#specialtyid').val().toLowerCase(); $rows.each(function(index, tr) { info = $(tr).find('td:nth-of-type(1)').text().toLowerCase(), specialty = $(tr).find('td:nth-of-type(2)').text().toLowerCase(); if ((info.indexOf(infovalue) != -1) && (specialty.indexOf(specialtyvalue) != -1)) { $(this).show(); } else { $(this).hide(); } }); if ((searchVal1 === '') && (searchVal2 === '')) { $rows.show(); } });});
使用一個輸入字段和一個選擇對HTML表進行排序-Javascript
一只名叫tom的貓
2021-04-28 22:22:59