option选中设置

selg1984 2013-04-24 06:45:30
我option是jquery动态生成的 如何让我选择的option具有selected属性

$("#Province").change(function () {
var select = $("#Province").val();
$("#CitySelect").get(0).options.length = 0;
$.getJSON("/Job/Pro2City", { 'Province': select }, function (data) {
$.each(data, function (i, item) {
//$("<option></option>").val(item["ID"]).text(item["Name"]).appendTo($("#cmb2"));
$("#CitySelect").append("<option value=" + item["Id"] + ">" + item["Name"] + "</option>");
//$("#CitySelect").children('option').attr('selected', 'selected');
});
var sal = $("#CitySelect").find("option");
sal.click(function () {
$(this).blur().attr('selected', 'selected');
});
if ($("#CitySelect").children('option').attr('selected') != undefined) {
$("#City").val($("#CitySelect").children('option').val());
}
});
})
...全文
193 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
深圳phper 2013-04-26
  • 打赏
  • 举报
回复
给option加动态id呗

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧