这里是我有一个正确填充选择列表:jquery设置选择的选项;不适用于动态添加选项工作,但确实为静态的
<select id="countriesList">
<option value="0"> -- select country -- </option>
<option value="500"> 500 </option>
</select>
<script type="text/javascript">
$(function() {
// load the countries list
$.getJSON(
"/StaticData/GetAllCountries/",
function (countries) {
// iterate each returned country and add it to the countries select list.
$.each(countries, function (i, country) {
$("#countriesList").append("<option value='" + country.Id + "'>" + country.Description + "</option>");
});
});
// set the selected country based on the model's delivered CountryId value
$('#countriesList').val(500);
});
</script>
人口的伟大工程,但在选择的一个调用.VAL()由脚本添加的元素不会使其被选中,但作为示例,静态定义的选项“500”在我调用.val()时正常工作。
我对jQuery相当陌生,但没有编程,因为我进入浏览器编程。任何提示都会有用。你还需要什么?
此脚本代码直接位于表td标签内,因此在呈现表单时填充并设置了选择。
谢谢。将.val()调用放在正确的位置后,完美地工作。那不是点击。谢谢! – slimflem 2011-01-28 15:56:05
你救了我的命!非常棒! – rubdottocom 2011-02-11 11:20:31