如何動態創建文本框,當我單擊添加按鈕。使用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