我在頁面中動態加載三個文本框,點擊時需要帶有文本框的ID。如何獲取動態加載的文本框的ID -jquery
$.ajax({
url: "../taxClass/getTaxClass",
type: "post",
contentType: "application/json",
dataType: "json",
success: function (data) {
var taxClassBOs = data.taxClassBOs;
$.each(taxClassBOs, function (key, value) {
$("#taxVatId").append('<div><label class="col-sm-3 control-label" for="VatId">' + value.description + '</label></div><div class="col-sm-3"><input type="text" name="vatId" value=""placeholder="' + value.title + '" id="' + value.taxClassId + '" class="form-control" /></div>');
});
}
});
我已經試過這個代碼
$('input[type="text"]').click(function() {
var id = $(this).attr('id');
alert(id);
});
的[事件綁定上動態創建的元素?]可能重複(http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – Balachandran