//wait for our page to be created by jQuery Mobile
$(document).delegate('#page-id', 'pageinit', function() {
//cache the elements we want to show/hide based on the search input
var $filterDivs = $('.filter-div');
//bind an event handler to the search input for when it's value changes
$('#search').bind('keyup change', function() {
//if the value of the input is nothing, then show all the elements
if (this.value == '') {
$filterDivs.slideDown(500);
//otherwise find only the elements that match what's in the search input
} else {
//create a regular expression based on the value of the search input
var regxp = new RegExp(this.value),
//get only the elements that match the search term(s)
$show = $filterDivs.filter(function() {
return ($(this).attr('data-filter').search(regxp) > -1);
});
//hide the elements that do not match
$filterDivs.not($show).slideUp(500);
//and show the elements that do match
$show.slideDown(500);
}
});
});
데모 : 여기
http://jsfiddle.net/jasper/cZW5r/1/는 기본 HTML이다 이 구조는 다음을 사용합니다.
<div data-role="fieldcontain">
<label for="search">Search Input:</label>
<input type="search" name="password" id="search" value="" />
</div>
<div class="filter-div" data-filter="one">1</div>
<div class="filter-div" data-filter="two">2</div>
<div class="filter-div" data-filter="three">3</div>
<div class="filter-div" data-filter="four">4</div>
<div class="filter-div" data-filter="five">5</div>
data-filter
특성에 유의하십시오. 이들은 검색 조건과 비교하여 검사되는 특성입니다.
응답 해 주셔서 감사합니다. – partialdata