日期:2014-05-16  浏览次数:20439 次

jsp页面上有一个button, 点击一次增加一个文本框,当文本框为四个时,自动换行

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

?<HEAD>

? <TITLE> New Document </TITLE>

? <META NAME="Generator" CONTENT="EditPlus">

? <META NAME="Author" CONTENT="">

? <META NAME="Keywords" CONTENT="">

? <META NAME="Description" CONTENT="">

?</HEAD>

<script type="text/javascript"> ??

String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) { ??

? ? if (!RegExp.prototype.isPrototypeOf(reallyDo)) { ??

? ? ? ? return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith); ??

? ? } else { ??

? ? ? ? return this.replace(reallyDo, replaceWith); ??

? ? } ??

} ??

</script> ?

?

<script>

var nHtml = '';

function addInput(){

var d = document.getElementById("t");

var html = nHtml;

//html.replace(/'<br>'/g,"");

html.replace(/(\n|\r|(\r\n)|(\u0085)|(\u2028)|(\u2029))/g, ""); ?

//alert(html);

html+="<INPUT type='text'/>";

var arr = html.split("<INP");

var row = parseInt((arr.length-1)/3);

var y = (arr.length-1)%3;

var h='';

for(var i=0;i<row;i++){

h+="<INP"+arr[i*3+1];

h+="<INP"+arr[i*3+2];

if(arr[i*3+3].indexOf("<br>")>0){

h+="<INP"+arr[i*3+3];

}else{

h+="<INP"+arr[i*3+3]+"<br>";

}

}

for(var i=0;i<y;i++){

h+="<INP"+arr[row*3+i+1];

}

nHtml=h;

d.innerHTML = h;

}

</script>

?<BODY>

?<input type="button" ?onclick="addInput();" value="add"/>

? <div id="t"><input type="text"/></div>

?</BODY>

</HTML>

<script>

nHtml = document.getElementById("t").innerHTML;;

</script>