清除jQuery Mobile多选列表

时间:2015-01-09 14:41:23

标签: jquery jquery-mobile

我有一个页面元素

<select name="geoLocationIndicatorClassID" id="int_geoLocationIndicatorClassID" multiple="multiple" data-native-menu="false">

动态生成元素

$('#int_geoLocationIndicatorClassID').append($('<option></option>').val(results.rows.item(i).geoLocationIndicatorClassID).html(results.rows.item(i).geoLocationIndicatorClassName));

结果是Sql对象。

我的问题是在用户提交数据时清除列表。

我试过了

$('#int_geoLocationIndicatorClassID a').each(function(){ 
$(this).removeClass('ui-checkbox-on').addClass('ui-checkbox-off');
});

$('#int_geoLocationIndicatorClassID :selected').each(function(i, selected){ 
$(selected).attr("selected", false);
$(selected).removeClass('ui-checkbox-on').addClass('ui-checkbox-off');
});

$('#int_geoLocationIndicatorClassID').selectmenu('refresh'); 

$("#int_geoLocationIndicatorClassID option:selected").removeAttr("selected");

但这并没有明确选择。是否有更好的方法来清除动态生成的多个选择?

2 个答案:

答案 0 :(得分:0)

尝试一下:$(&#34; #int_geoLocationIndicatorClassID选项:选择&#34;)。prop(&#34;选择&#34;,false);

答案 1 :(得分:0)

$("#int_geoLocationIndicatorClassID").val([]).selectmenu('refresh', true);

refresh() 方法的true会强制jQM在将选定的val设置为空数组后重建窗口小部件。