我想从api获取json响应,并因此在JQuery中为HTML中的动态添加DOM元素做事件。获取JSON响应为每个动态添加索引DOM元素与JQuery
我可以显示每个索引元素的json消息。
function checkIdnAvailability() {
var jsonRsp = [];
$('.iin').each(function (index) {
var tb0001_idn_val = $('#iin'+index).val();
$.post("<?php echo site_url()?>college/idnCheck", {
tb0001_idn: tb0001_idn_val
}, function(response){
$('#loading').hide();
$('#message'+index).html('').html(response.message).show();
jsonRsp.push(response.message);
if($.inArray("data exists", jsonRsp)) {
$(':input[type="submit"]').prop('disabled', true);
}else {
$(':input[type="submit"]').prop('disabled', false);
}
});
}
)
}
这里我想说,如果我得到“数据存在”json响应我想禁用提交按钮。
问题是......? –
@JorgeFuentesGonzález代码不起作用! –
在.html(response.message)之前不需要调用'.html('')',因为'.html()'将完全取代那里的任何东西。 – Barmar