/* my jquery code */
(function($){
$.fn.tableSearch = function(options){
if(!$(this).is('table')){
return;
}
var tableObj = $(this),
searchText = (options.searchText)?options.searchText:'Search: ',
searchPlaceHolder = (options.searchPlaceHolder)?options.searchPlaceHolder:'',
divObj = $('<div style="float:left;">'+searchText+'</div><br /><br />'),
inputObj = $('<input type="text" placeholder="'+searchPlaceHolder+'" />'),
caseSensitive = (options.caseSensitive===true)?true:false,
searchFieldVal = '',
pattern = '';
inputObj.off('keyup').on('keyup', function(){
searchFieldVal = $(this).val();
pattern = (caseSensitive)?RegExp(searchFieldVal):RegExp(searchFieldVal, 'i');
tableObj.find('tbody tr').hide().each(function(){
var currentRow = $(this);
currentRow.find('td').each(function(){
if(pattern.test($(this).html())){
currentRow.show();
return false;
}
});
});
});
//以下是表之前的appendind div。我想要div(divObj)将附加在另一个div上 tableObj.before(divObj.append(inputObj)); return tableObj;
}
}(jQuery));
/* my php file */
<script type="text/javascript">
$(document).ready(function(){
$('table#search-table').tableSearch({
searchText:'Search From Table ',
searchPlaceHolder:' Input Value'
});
});
</script>