无法为下拉列表设置默认值
Unable to set the default value for drop down list?
在我的应用程序中有一个下拉列表,其中的值动态地来自数据库。如果我在下拉列表中选择任何类别值,然后选择菜单,如果我重置数据库,我需要清除下拉的选择值,并设置默认值"选择类别"。但是我无法清除下拉列表中的选定值。
我的代码如下,
脚本:
<script>
function resetconformation()
{
var x;
var r=confirm("Do you want to reset database!");
if (r==true)
{
var db = window.sqlitePlugin.openDatabase({name: "MYDB"});
db.transaction(function (tx) {
tx.executeSql('DROP TABLE IF EXISTS Locationlog');
});
//$('#select-choice option:contains("Select Category")').prop('selected',true);
$("#select-choice").empty();
$("#locationList").empty();
$("#maillocation").hide();
var optionheading = '<option value="Select Category">Select Category</option>';
$("#select-choice").append(optionheading);
$("#select-choice").refresh();
$('#select-choice option:contains("Select Category")').prop('selected',true);
$('#select-choice option[value="Select Category"]').attr('selected',true);
}
else
{
}
}
</script>
HTML:
<select name="select-choice" id="select-choice" data-mini="true" data-theme="a" style="width:230px">
选择类别
重置数据库后如何设置默认值"Select Category"?任何建议. .
示例:http://jsfiddle.net/Gajotres/tN56D/1/
你少了一个bug行:
$("#select-choice").selectmenu('refresh', true);
每一个动态添加的内容必须手动增强,jQuery Mobile不会为你做。
为什么不直接
var sel = $("#select-choice").get(0); // get the DOM object
sel.options.length=1; // no need to delete all and add the Select Category each time
sel.selectedIndex=0;
相关文章:
- jQuery Datepicker从日期开始设置默认值
- 在KeystoneJS中为Types.Money设置默认值
- 如何为显示jquery滑块值的文本框设置默认值
- 在Bootstrap下拉菜单中设置默认值
- 如何为 jquery 自动完成框设置默认值
- 聚合物:如何为具有嵌套特性的图纸选项卡设置默认值
- 使用复杂对象上的删除为选择框手动设置默认值
- 在动态输入数据的下拉菜单中设置默认值
- 有什么方法可以在超级测试中设置默认值吗
- 挖空 + 选择2 -- 设置默认值
- ||运算符在 null 时不设置默认值
- 如何在 Select2 输入中设置默认值,并在 asp.net mvc 中标记
- 在链接回以前访问过的页面时设置默认值
- PHP 设置默认值以从 ajax 页面返回记录
- 在文档加载时使用 JQuery 在下拉字段中设置默认值
- 如何为 Google 放置 API 自动完成文本框设置默认值
- 为具有未定义值的嵌套对象设置默认值的最简单方法
- AngularJS更新ng-model的值以设置默认值
- 剑道 UI 组合框 - 设置默认值
- JQuery 日期选取器设置默认值