У меня есть этот скрипт для таблицы фильтров: (измените этот скрипт на функцию)
$(document).ready(function(){
var $rows = $('tbody > tr'),
$filters = $('#tableP input');
$filters.on("keyup", function () {
var $i = $filters.filter(function () {
return $.trim(this.value).length > 0;
}),
len = $i.length;
if (len === 0) return $rows.show();
var cls = '.' + $i.map(function () {
return this.className
}).get().join(',.');
$rows.hide().filter(function () {
return $('td', this).filter(cls).filter(function() {
var content = this.textContent.toLowerCase(),
inputVal = $i.filter('.' + this.className).val().toLowerCase();
return content.indexOf(inputVal) > -1;
}).length === len;
}).show();
});
});
<script src="http://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript"></script>
<table id='tableP'>
<thead>
<tr>
<th>
<input type='text' class="nome" placeholder="Nome.."/>
</th>
<th>
<input type='text' class="cognome" placeholder="Cognome.." />
</th>
<th>
<input type='text' class="citta" placeholder="Città.." />
</th>
</tr>
</thead>
<tbody>
<tr>
<td class='nome'>Carlo</td>
<td class='cognome'>Grasso</td>
<td class='citta'>Italia</td>
</tr>
<tr>
<td class='nome'>Giuseppe</td>
<td class='cognome'>Puglisi</td>
<td class='citta'>Italia</td>
</tr>
<tr>
<td class='nome'>Franc</td>
<td class='cognome'>Justin</td>
<td class='citta'>Francia</td>
</tr>
</tbody>
</table>
Это работает!Я хочу создать функцию для вызова во входном теге, я не знаю, как это сделать.Я хочу создать функцию для вызова во входном теге, я не знаю, как это сделать.
Я хочу создать функцию для ввода тега onkeyup myFilter()
, как я могу это сделать?Кто-нибудь может мне помочь?