您好我有一個web窗體,我需要根據上一個文本框中的條目動態添加多個文本框。即使輸入了一個字符以前的文本框應該產生它旁邊新texbox沒有從以前的文本框失去焦點,它應該讓我不限制進入儘可能多的字符.. 這裏是我的代碼:動態創建多個文本框,取決於以前的文本框中的最小字符數/ javascript/asp
getId = function()
{
var id = 1;
return function()
{
id++;
}
}
function CreateTextbox()
{
var box = document.getElementById("divCreateTextbox");
var curr = 'txt' + getId();
var inp = document.createElement('input');
inp.type = 'text';
inp.name = 'textfield';
inp.setAttribute("id", curr);
inp.setAttribute("minlength",'1');
box.appendChild(inp);
inp.setAttribute('onkeyup', 'moveOnMin(this)');
inp.focus();
}
function moveOnMin(s)
{
if(s.value.length >= parseInt(s.getAttribute("minlength")))
{
CreateTextbox();
}
問題與上面的代碼是,它只是讓我輸入1個字符一個文本框,並將焦點轉移到新的文本框上。每次我嘗試在文本框中輸入多個字符時,都會爲每個字符創建新的文本框。任何解決方案
我打電話的功能
只加一次<腳本類型= 「文本/ JavaScript的」> 的window.onload =函數() { CreateTextbox() } – Rithu 2013-05-09 13:14:53