【发布时间】:2011-04-01 18:00:22
【问题描述】:
我有一个 id 为 other 的文本框,我想将此文本框值填充到下拉列表中 这是我用来填充的 jquery...但这不起作用..而且我正在使用 jquery mobile..此脚本适用于普通 jquery,但一旦我使用 jquery mobile 它就不起作用......任何建议将不胜感激......!我想这样做:- http://viralpatel.net/blogs/demo/dynamic-combobox-listbox-dropdown-in-javascript.html
<script>
function addCombo() {
var optName = $("#other").attr("value");
$('#category').append("<option value='"+ optName + "'>" + optName + "</option>");
$("#other").attr("value", "");
$('#category').selectmenu('refresh', true);
}
</script>
这是下拉列表的代码
<td>Category</td>
<td><select class="size" id="category" name="category" width="30px">
<option width="30px" value="" selected="selected" >Select</option>
<option value="food">Food</option>
<option value="rent">Rent</option>
<option value="gas">Gas</option>
<option value="enter">Entertainment</option>
<option value="grocery">Grocery</option>
<option value="general">General</option>
<option value="other">Other</option></select></td>
</tr>
<tr>
<td>Other</td>
<td><input type="text" id="other" name="other"/></td>
<td><input type="button" data-role="button" value="Add" onclick="addCombo()"></td>
</tr>
【问题讨论】:
标签: jquery-mobile