2015-01-16 86 views
0

我使用JQuery mobile 1.0.1。jQuery Mobile Pagebeforeshow和longlist selectmenu

我創建了一個頁面,下面的代碼

<div data-role="page" id="homecomments"> 
    <div data-role="header"> 
     <h1>Comments</h1> 
     <a href='#home' class='ui-btn-left' data-icon='home' data-theme="a" data-iconpos="notext">Home</a> 
    </div> 
    <div data-role="content"> 
     <select name="building" id="opt1" data-native-menu="false"> 
     <option>building</option> 
     </select> 
    </div> 
</div> 

我呼籲與

$('#homecomments').live('pagebeforeshow', function() { 
    getTitlesComments() 
}); 

$(document).delegate("#homecomments", "pagecreate", function() { 
    $("#opt1").change(function() { 
    if ($("#opt1 option:selected").val() != 0) { 
     ====================DO SOMETHING======================= 
    } 
}); 

function getTitlesComments() { 
    $('#opt1').val(''); 
    $("#opt1").selectmenu('refresh'); 
    ==========dynimicaly create longlist selectmenu opt1======== 
} 
012頁

我必須在選擇菜單中使用長列表。每當我從長列表中選擇選擇菜單。

我該如何解決這個問題?

回答

1

長列表選擇是「隱藏」頁面,所以當你選擇後返回時,它將再次「顯示」它。好消息是它仍然保留你的選擇。您可以在頁面顯示代碼前查看它們是否存在,並在代碼再次創建選項列表時選擇值。

$("#opt1").selectedValues().join(","); 

會給你一個逗號分隔的列表來處理。

相關問題