在“添加和编辑”表单中,我调用了jquery下拉列表更改方法。它适用于添加表单,但如果从数据库中获取下拉值,则无法调用更改方法。我们可以明确地触发改变方法吗?
var stateid = '<?php echo $dbval['stateid']; ?>';
$("#stateid").change(function() {
if(true == isEmpty($("#stateid").val())) {
$("#stateid").focus();
return false;
}
$.ajax({
url: '<?php echo base_url(); ?>admin/health/loadCommonDataAjax/',
data: { dataType: 'state', dataVal: $("#stateid").val()},
dataType: 'json',
success: function(responseData) {
if(responseData.result=='success') {
$("#districtid").empty().append("<option value=''>Select District First</option>");
var districtlength = responseData.districts.length;
for(var i=0; i<districtlength; i++) {
$("#districtid").append("<option value='"+responseData.districts[i].district_id+"'>"+responseData.districts[i].district_name+"</option>");
}
}
},
type: 'POST'
});
});