当前位置: 代码迷 >> JavaScript >> #初学者问个有关问题:动态调整文本框个数#
  详细解决方案

#初学者问个有关问题:动态调整文本框个数#

热度:163   发布时间:2012-03-15 11:50:39.0
##################菜鸟问个问题:动态调整文本框个数#####################
用户选择下拉框,分i步完成任务,然后下面立刻给出i个文本框让他输入预计完成日期,
其中1 <=i <=5


请问该怎么用js实现呢?

着实菜鸟,就有点基本js知识,但这个东西程序中用到了,只好请大虾帮忙,然后我在回去好好学习,补上js这一课.

小弟感激不尽.

------解决方案--------------------
<html>
<head>
<script>
function myFun()
{
var ddl = document.getElementById( "sel ");
var txt0 = document.getElementById( "txt0 ");
var txt1 = document.getElementById( "txt1 ");
var txt2 = document.getElementById( "txt2 ");
var txt3 = document.getElementById( "txt3 ");
//
switch ( ddl.options[ddl.selectedIndex].value )
{

case "-1 ":

txt0.style.display = "none ";
txt1.style.display = "none ";
txt2.style.display = "none ";
txt3.style.display = "none ";
case "0 ":
txt0.style.display = " ";
txt1.style.display = "none ";
txt2.style.display = "none ";
txt3.style.display = "none ";

break;
case "1 ":
txt0.style.display = " ";
txt1.style.display = " ";
txt2.style.display = "none ";
txt3.style.display = "none ";
break;
case "2 ":
txt0.style.display = " ";
txt1.style.display = " ";
txt2.style.display = " ";
txt3.style.display = "none ";
break;
case "3 ":
txt0.style.display = " ";
txt1.style.display = " ";
txt2.style.display = " ";
txt3.style.display = " ";
break;

}
}
</script>
</head>
<body>


<select id= "sel " onChange= "myFun(); ">
<option value= "-1 "> 请选步骤 </option>
<option value= "0 "> 第一步 </option>
<option value= "1 "> 第二步 </option>
<option value= "2 "> 第三步 </option>
<option value= "3 "> 第四步 </option>
</select>
<input type= "text " id= "txt0 " style= "display:none ">
<input type= "text " id= "txt1 " style= "display:none ">
<input type= "text " id= "txt2 " style= "display:none ">
<input type= "text " id= "txt3 " style= "display:none ">

</body>
</html>
我做了一个简单的例子,不知道对你有没有帮助
------解决方案--------------------
<script language= "JavaScript ">
function setfocus()
{
document.form1.marking.focus();
}
</script>
<script language= "javascript ">
var j=0
function add_row(){
k=j+1
j=sqd.rows.length;
newRow=document.all.sqd.insertRow(-1)
newcell=newRow.insertCell()
newcell.style.backgroundColor= '#f7f7f7 '
newcell.innerHTML=j
newcell=newRow.insertCell()
newcell.style.backgroundColor= '#f7f7f7 '
newcell.innerHTML= " <input name=Number type=radio > "
newcell=newRow.insertCell()
newcell.style.backgroundColor= '#f7f7f7 '
//*************************update************************************
newcell.innerHTML= " <input name=Marking type=text class=INPUT1 size=30 style=font-size: 20px; font-weight: bold onblur= 'onBlurValue() '> "
  相关解决方案