获取 Uncaught TypeError: Cannot set property 'innerHTML' of null。如何修复它。
$(window).load(function() {
document.getElementById("id_city").innerHTML = ('<option>Select a City</option>');
var selected_state = $('#id_state').val();
var selected_city = $('#selected_city').val();
var data = 'state='+selected_state + '&selected_city='+selected_city;
var url = $('#url').val();
$.ajax({
type:"POST",
url:url,
data:data, // multiple data sent using ajax
success: function (response) {
document.getElementById("id_city").innerHTML=response;
}
});
});
最佳答案
这个错误意味着在这一行:
document.getElementById("id_city").innerHTML
你有
document.getElementById("id_city") = null
请确保您有任何标记将 id 参数设置为“id_city”
关于javascript - 无法在 Jquery 中设置 null 的属性 'innerHTML',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41613641/