使用jquery添加选定数量的文本框 [英] Add selected number of text boxes using jquery
本文介绍了使用jquery添加选定数量的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将文本框添加到我的div中。文本框的数量由选择列表给出。
I want to add text boxes to my div. The number of text boxes is give by selection list.
<DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript"></script>
</head>
<body>
<div id = "text">
Choose No.of TextBoxes:
<select id = "options">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br/>
</div>
</body>
推荐答案
试试这个
Try This One
$(document).ready(function()
{
$("#options").change(function()
{
//Find if there is already a input box
//if yes then remove it
$("#text").find("input").remove();
var count = $(this).val();
for (var i = 1; i <= count; i++) {
var ipBoxName ="myInput"+i;
var ipBox = ' <input type="textbox" name="'+ipBoxName+'" />';
$('div#text').append(ipBox);
}
});
});
这篇关于使用jquery添加选定数量的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文