我正在以javascript动态表单创建动态表单,其中有一个将添加文本字段的按钮。我想捕获那些用户输入的文本框的值,我想将其打印出来。但直到现在仍无法获得...
在Java脚本中,我创建了在单击添加按钮时创建文本框的功能。我想捕捉文本框的价值
下面是我的html
<div v-for="(n, index) in imagesArr" :class="index === 0 || index === 1 ? 'col-6' : 'col-4'" style="padding: .5rem">
<img :src="n" :alt="'Zdjęcie jachtu nr ' + index" class="img-fluid">
</div>
我的烧瓶代码:
<html>
<head>
<title>Payment Plan Form</title>
<script type="text/javascript" src="{{url_for('static', filename='vendor/jquery/jquery-3.2.1.min.js')}}"></script>
<a href ="/" style="text-align:right-side;display:block;">Log Out</a>
<a href ="/tco" style="text-align:right-side;display:block;">Visit TCO</a>
<style type="text/css">
div{
padding:8px;
}
</style>
</head>
<body>
<h1 align="center">Payment Plan Form </h1>
<script type="text/javascript">
$(document).ready(function() {
var max_fields = 100; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //wants to capture value of below div text name is mytext[]
$(wrapper).append('<div><input type="text" name="mytext[]"/>  <input type="text" name="mytext[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
</head><body>
<form action="" ALIGN="CENTRE" method="POST">
<div class="input_fields_wrap"align="center">
<button class="add_field_button">Add More Fields</button>
</div>
<div align="center">
<input type="submit" value="Submit"><br>
</div>
<TR><TD>
XID Number </TD>
<TD><input type="text" name="xidnumber">
</TD>
</TR>
</form>
</body>
</html>