示例:http: //jsfiddle.net/FyLr9/
我有一个 jQueryMobile 1.3 应用程序的搜索功能,可以从中添加或删除过滤器。我需要获取并存储选择列表值(可以),然后将其应用于搜索输入的名称属性。
HTML:
<div class="js-select" data-role="fieldcontain">
<label for="search" class="select">Search By</label>
<select data-role="none" name="select2[]" class="mySelect" data-theme="e">
<option value="1" selected="selected" > Search1</option>
<option value="2" >Search2</option>
<option value="3" >Search3</option>
</select>
<div style="width:100%;height:10px;display:block;"></div>
<label for="search">Search For</label>
<input type="search" name="" id="search" class="inline" value="" placeholder="Search" data-theme="d" data-inline="true">
<a type="button" class="closeselect" id="remove" data-icon="minus" data-iconpos="right" data-inline="true" data-theme="d" data-mini="true">Delete Filter</a>
</div>
JS/jQuery :
$(function(){
$('form').on('change', '.mySelect', function() {
var value = $(this).val();
//alert to show I'm getting the value
alert (value);
$(this).next('input[type="search"]').attr('name') = value;
});
});