2013-06-23 39 views
0

例匹配值: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; 
    }); 
}); 
+1

'[data-type = search]'或'[type = text]'JQM將輸入搜索更改爲data-type =搜索標記增強。 – Omar

回答

1
$(this).nextAll('input[type="search"]').attr('name',value); 

http://jsfiddle.net/FyLr9/3/

從奧馬爾的評論只是使用ID來選擇元素

$(this).nextAll('#search').attr('name',value); 
+0

似乎是對的,雖然不工作 –

+0

@DirtyBirdDesign你通過我間隔 – Musa

+1

jQuery手機是不同的。放輕鬆=)檢查這個http://stackoverflow.com/questions/16972701/how-to-remove-the-blue-halo-glow-from-jquery-mobile-input-elements-that-receive/16973025#16973025 – Omar