[英]Javascript getting the values of an array of input boxes
I have an input field that has a button to dynamically add another input field and I am trying to get it so that when I click plot
i am able to grab the content inside the input fields gps[]
我有一个输入字段,该字段具有一个按钮,可以动态添加另一个输入字段,而我尝试获取它,以便在单击
plot
时,我能够在输入字段gps[]
获取内容。
html HTML
<div id="marker">
<input type="text" name="gps[]" id="gps">
<input type="text" name="gps[]">
</div>
Plot 情节
javascript 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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.