我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());
}
});
})
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());
}
});
})
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货