<分区>
我正在尝试获取更改元素的 id 的详细信息。 但是当我试图使用下面的代码找到它时,它给出了错误。
HTML:
<input type="text" required="required" placeholder="Enter city name" class="get_neighborhood" maxlength="30" id="city" value="P" name="city" data-invalid="">
<input type="text" placeholder="State code" maxlength="2" class="get_neighborhood" required="required" id="state" value="AA" name="state">
JS:
$(document).ready(function() {
$(".get_neighborhood").on('change',function() {
city = $('#city').val();
ajax_url = 'alternate_address/ajax_get_country/';
$.ajax({
type: 'POST', // or 'POST', whatever you want.
dataType: 'json', // output_value will be a plain text string.
data: {
city: city
},
url: ajax_url,
beforeSend: function(msg) {
},
success: function(output_value) {
myid = $(this).attr('id');
//var id=this.id;
console.log(myid.toSource());
},
error: function(output_value) {
alert('err');
}
});
});
});
这给出了 myid 未定义的错误。 当我更改城市或州字段时。