2
我有一個輸入字段,有一個按鈕來動態添加另一個輸入字段,我試圖獲得它,所以當我點擊plot
我能夠抓住內部的內容輸入字段gps[]
Javascript獲取輸入框數組的值
HTML
<div id="marker">
<input type="text" name="gps[]" id="gps">
<input type="text" name="gps[]">
</div>
情節
的JavaScript
var counter = 1;
var limit = 3;
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "<input type='text' name='gps[]'>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
$('body').on('click','.plot', function(){
var y = $('input[name="gps[]"]').val();
console.log(y);
});