如何动态创建文本框,当我单击添加按钮。使用javascript或jquery验证
我把输入栏放在文本框中。
如何使用javascript或jquery验证动态创建的文本框。
<html>
<head>
<title>Adding and Removing Text Boxes Dynamically</title>
<script type="text/javascript">
var intTextBox=0;
//FUNCTION TO ADD TEXT BOX ELEMENT
function addElement(){
intTextBox = intTextBox + 1;
var contentID = document.getElementById('content');
var newTBDiv = document.createElement('div');
newTBDiv.setAttribute('id','strText'+intTextBox);
newTBDiv.innerHTML = "Text "+intTextBox+": <input type='text' id='" + intTextBox + "' name='" + intTextBox + "'/>";
contentID.appendChild(newTBDiv);
}
</head>
<body>
<p>Demo of Adding and Removing Text Box Dynamically using JavaScript</p>
<p><a href="javascript:addElement();" >Add</a>
<a href="javascript:removeElement();" >Remove</a>
</p>
<div id="content"></div>
<input type="button" value="submit"/>
</body>
</html>
当我点击提交按钮,所有的文本框验证必须完成之后....
你是什么 “验证文本” 是什么意思?检查它是否存在?验证用户添加到其中的输入?你是什么意思“动态创建文本框 - 当发生什么事件时动态创建? – alfasin 2012-02-27 07:51:46
是验证动态创建的文本框....是否有可能? – specialuser 2012-02-27 07:53:37
当然,当你创建文本框时用ID指定它,然后使用getElementById()以确保它存在 – alfasin 2012-02-27 07:54:45