我創建了一個div動態並附加到div。我試圖從查詢中添加數據並將其加載到該文本字段中。但是,我無法選擇動態創建的元素,因爲它在DOM中不可見,因爲它已經加載。 這是我fiddle選擇動態創建的元素
<div id="parent">
<input id='childButton' type="button" value="Add"/>
<div id="child" data-row="0">
<input type="text" value="" />
</div>
</div>
var rowNum = 0;
$('#parent').on('click', '#childButton', function() {
var clone = $('#child').clone().attr('data-row', ++rowNum);
$('#parent').append(clone);
console.log($('#child[data-row=1]').length);
});
同'克隆元素id'是問題 – nikhil
解釋**無法選擇動態創建的元素**。你如何選擇? – Manwal