Vik*_*kas 6 html javascript jquery-mobile
第一次,当我加载页面时,我的选择框为空:
<select name="secondaryTitle" id="secondaryTitle"></select>
Run Code Online (Sandbox Code Playgroud)
然后我进行ajax调用并获取上面选择框的json数据.
arrtitle = objSecTitle.getAllSecondaryTitle(serviceId); // its an ajax call, that returns json object
var obj = jQuery("#secondaryTitle");
removeAllOptions(obj);
for(i=0;i<arrtitle.length;i++)
{
obj.options.length=obj.options.length + 1;
obj.options[obj.options.length - 1].text = arrtitle[i][1];
obj.options[obj.options.length - 1].value = arrtitle[i][0];
}
function removeAllOptions(selectbox){
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
selectbox.remove(i);
}
}
Run Code Online (Sandbox Code Playgroud)
我的ajax电话很完美.上面的代码也会更改下拉项.但是当我们使用jQuery Mobile时,UI不会更新,因为它显示/隐藏选择弹出窗口的不同div.
Vik*_*kas 14
没关系!
我应该正确检查文件:
//refresh value
$('#select').selectmenu('refresh');
//refresh and force rebuild
$('#secondaryTitle').selectmenu('refresh', true);
Run Code Online (Sandbox Code Playgroud)