2011-10-05 98 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+版本。那是我的问题。 –

相关问题