JS  選択した値で絞り込む

セレクトボックスから選択
JS
jQuery(function ($) {

// セレクトボックスが変更されたら処理をする
$('#pref-select').change(function () {

// 選択した値を取得
var select_val = $('#pref-select option:selected').val();
$.each($("#pref-table tbody tr"), function (index, element) {

var txt = $(element).find("td a:eq(0)").text();
//var txt = $(this).find("td a:eq(0)").html();
if(txt.match(select_val) != null){
$(element).css("display", "table-row");
}else{
$(element).css("display", "none");
}
});
});
});

HTML

フリーテキスト検索ボタン
JS
$(function(){
$('#button').bind("click",function(){
var re = new RegExp($('#search').val());
$('#pref-table tbody tr').each(function(){
var txt = $(this).find("td a:eq(0)").html();
if(txt.match(re) != null){
$(this).show();
}else{
$(this).hide();
}
});
});

$('#button2').bind("click",function(){
$('#search').val('');
$('pref-table tbody tr').css("display", "table-row");
});
});

Javascript,WEB

Posted by admin