我正在设置值下拉但是它没有插入。为什么?但我在另一个例子中做同样的事情,我得到了结果。
<div data-role="fieldcontain">
<label for="text-12" style="text-align:left;margin-left: 0px;"> Font Type:</label>
<select name="select-choice-1" id="select-choice-1" class="fontFamily_h">
<option>Select Font </option>
<option value="AntiquaAntiqua">AntiquaAntiqua</option>
<option value="Arial">Arial </option>
<option value="Times New Roman">Times New Roman</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="text-12" style="text-align:left;margin-left: 0px;">Font Size:</label>
<select name="select-choice-1" id="select-choice-2" class="fontSize_h">Select Size
<option>Select Size</option>
<option value="9">9 px</option>
<option value="10">10 px</option>
<option value="11">11 px</option>
<option value="12">12 px</option>
<option value="13">13 px</option>
</select>
</div>
$(document).on('click', '.default_h', function(event) {
var i =12;
alert("Hi"+ $('#select-choice-2').val()); getting select Size
$('#select-choice-1').val('Arial').selectmenu("refresh");
$('#select-choice-2').val('12 px').selectmenu("refresh");
alert("Hi"+ $('#select-choice-1').val()); getting Arial
alert("Hi"+ $('#select-choice-2').val());;getting select Size
});
我正在获得Arrial但是在第二个例子中我没有得到12 px
答案 0 :(得分:2)
您需要将val()
属性设置为实际的值属性,而不是文本:
$('#select-choice-1').val('Arial').selectmenu("refresh");
$('#select-choice-2').val('12').selectmenu("refresh");