例匹配值:http://jsfiddle.net/FyLr9/更改文本輸入name屬性從選擇列表
我有一個搜索功能的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;
});
});
'[data-type = search]'或'[type = text]'JQM將輸入搜索更改爲data-type =搜索標記增強。 – Omar