以下jquery代码完美地运行,我只想更改在表之前附加的过滤器,我想在另一个div上追加该div。

时间:2015-11-06 05:52:53

标签: javascript

/* 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>

0 个答案:

没有答案