2011-10-05 27 views
1

使用PhoneGap,我有一個呈現爲包含2個選項的UIPicker的元素。 到目前爲止,我沒有以編程方式將第二個選項設置爲選定的選項。PhoneGap iOS UIPicker等效元素:以編程方式選擇選項值

這是怎樣的代碼看起來像(JavaScript)的:

<select id="dropdown1" onchange"doSomething()"> 
    <option value="0">none</option> 
    <option value="1">test</option> 
</select> 

  • 我已經沒有選擇使用 '的selectedIndex',即

    $(「選擇#第二個選項dropdown1「)。selectedIndex = 1;

  • 我還沒有選擇的第二選項訪問 '選擇' 屬性,即

    $( 「選擇#dropdown1選項」)[1] .attr( 「選擇」, 「選擇」);

現在看一下上面兩行代碼生成的html,innerHTML保持不變,選定的屬性不會出現。我不知道刷新GUI的方法。任何人都可以闡明我做錯了什麼,或者我錯過了什麼?

謝謝。

Yohann

回答

1

你需要確保以刷新jQuery Mobile的控制,讓漂亮的圖形顯示更新爲對應於底層的HTML標籤。試試這個(http://jsfiddle.net/NPC42/m4jMn/4/):

// remove current selection 
$("select#dropdown1 option").removeAttr("selected"); 

// add selected, and then refresh the parent control to see result 
$("select#dropdown1 option[value='1']").attr('selected', 'selected').parent().selectmenu("refresh"); 

這適用於我。

+0

IIT不適用於JQuery版本1.4.x.它適用於1.6+版本。那是我的問題。 –

相關問題