jsp自动分成几行的写法
jsp自动分成几行的写法,比如我要在一个文本输入框内输入3,点击按钮;自动跳出三行文本框之类的,有源代码的请提供一下;我猜也就是JS的写法了.email:jhcff88@sohu.com
------解决方案--------------------onclick= 'insertInputText(3) '
function insertInputText(vIn) {
var s = " ";
for(var i=0;i <vIn-1;i++) {
s = s + " <input type= 'text '.... /> ";
}
var obj = document.getElementById( "test ");
obj.innerHTML = s;
}
------解决方案--------------------stefli() 说得对,可能你没理解好
function insertInputText(vIn) {
var s = " ";
for(var i=0;i <vIn-1;i++) {
s = s + " <input type= 'text '/> ";
}
var obj = document.getElementById( "test ");
obj.innerHTML = s;
}
你需要在页面上放一个id为test的容器来装这些text,比如你用div,完整代码如下
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
</head>
<script language= "javascript ">
function insertInputText(vIn) {
var s = " ";
for(var i=0;i <vIn;i++) {
s = s + " <input type= 'text '/> ";
}
var obj = document.getElementById( "test ");
obj.innerHTML = s;
}
</script>
<body>
<form id= "form1 " name= "form1 " method= "post " action= " ">
<label> jack
<input type= "text " name= "textfield " />
</label>
<div id= 'test '> </div>
<input type= "button " name= "Submit " value= "提交 "onclick= 'insertInputText(3) ' >
</form>
</body>
</html>
------解决方案-------------------- 'insertInputText(3)中的参数3就是要生成的数量,这个例子是生成了三个,如果你想生成多个就换掉这个参数就行了
修改代码如下
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
</head>
<script language= "javascript ">
function insertInputText(vIn) {//vIn参数是要生成的数量
var s = " ";
for(var i=0;i <vIn;i++) {
s = s + "name: <input type= 'text ' size=10 id= ' "+i+ " '/> "+
"company: <input type= 'text ' size=10/> "+
" <select> <option> man </option> <option> woman </option> </select> <br> ";
}
var obj = document.getElementById( "test ");
obj.innerHTML = s;
document.getElementById(vIn-1).value = '月光鸟 ';//测试
}
</script>
<body>
<form id= "form1 " name= "form1 " method= "post " action= " ">
<label> jack
<input type= "text " name= "textfield " />
</label>
<div id= 'test '> </div>
<input type= "button " name= "Submit " value= "提交 "onclick= 'insertInputText(3) ' >
</form>
</body>
</html>