我对选择的ajax下拉值=在编辑或刷新时选择的问题感到困惑
<div class="form-group" id="maincat">
<label for="cat_desc" class="col-sm-2 control-label">Select State</label>
<div class="col-sm-10">
<select name="city_state" id="stateDrp">
<option value="">Please Select State</option>
</select>
</div>
</div>
function sel_city(val){
$.ajax({
url:"<?php echo
base_url();?>tdbadmin/countriesmanagement/getstate_drpdwn",
data: {id: val},
type: "POST",
success:function(data){
$("#stateDrp").html(data);
//$("#stateDrp").val(<?php echo $citydata[0]->country_id;?>);
}
});
}
setTimeout(function(){
sel_city(<?php echo $citydata[0]->country_id;?>);
}, 1000);
$("#stateDrp option[value='<?php echo $citydata[0]->country_id;?>']").attr("selected", "selected");
</script>
这是我尝试的但是我无法在下拉中获得所选值,请帮助
答案 0 :(得分:0)
试试这个:
$("#stateDrp option[value='<?php echo $citydata[0]->country_id;?>']").attr("selected", true);