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

##################菜鸟问个问题:动态调整文本框个数#####################
用户选择下拉框,分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.inn