当我更改列表值时,它显示“getstate未定义” 如何解决它
<select name="country" id="country" onchange="getstate();">
<option value="">select</option>
<option value="1">USA</option>
</select>
function getstate() {
var site_url = "<?php echo site_url();?>";
var countryid = $("#country").val();
if(countryid=="") {
$("#state").html('<option value="">select</option>');
$("#city").html('<option value="">select</option>');
return false;
}
$.get(site_url+"admin/ajxcal1",{'id':countryid},function(data){
console.log(data);
//$("#state").html(data);
});
}
答案 0 :(得分:0)
所有javascript代码都应该包含在脚本标记内。它应该工作。
<select name="country" id="country" onchange="getstate();">
<option value="">select</option>
<option value="1">USA</option>
</select>
<script>function getstate() {
var site_url = "<?php echo site_url();?>";
var countryid = $("#country").val();
if(countryid=="") {
$("#state").html('<option value="">select</option>');
$("#city").html('<option value="">select</option>');
return false;
}
$.get(site_url+"admin/ajxcal1",{'id':countryid},function(data){
console.log(data);
//$("#state").html(data);
});
}</script>
答案 1 :(得分:0)
将js函数添加到单独的.js文件或html中的脚本标记中,然后它将正常工作
答案 2 :(得分:0)
试试这个:
HTML:
<select name="country" id="country" onchange="getstate()">
<option value="">select</option>
<option value="1">USA</option>
</select>
jQuery的:
<script>
function getstate() {
var site_url = "<?php echo site_url();?>";
var countryid = $("#country").val();
if(countryid=="") {
$("#state").html('<option value="">select</option>');
$("#city").html('<option value="">select</option>');
return false;
}
$.get(site_url+"admin/ajxcal1",{'id':countryid},function(data){
console.log(data);
//$("#state").html(data);
});
}
</script>