如果只有一个输入字段,则自动完成工作得很好。但就我而言,我必须生成输入字段。所以无论如何这是我的代码。
HTML 部分
<div class="clonedInput" id="input1">
<div class="row" id="items">
<div class="col-md-4">
<div class="form-group">
<div class="input-group">
<span class="input-group-btn">
</span>
<input type="text" id="sug_input" class="form-control" name="title" placeholder="Search for product name">
</div>
<div id="result" class="list-group result"></div>
</div>
</div>
</div>
</div>
<input type="button" id="btnAdd" value="add another item" />
<input type="button" id="btnDel" value="remove item" />
Run Code Online (Sandbox Code Playgroud)
脚本部分
<script type="text/javascript">
$('#btnAdd').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
var newNum = new Number(num + 1); // the numeric ID of the …Run Code Online (Sandbox Code Playgroud)