<html>
<head>
<script>
function $G(v){return document.getElementById(v);}
function _dynadd(parentID,inputFileID, maxNum){
/**if (maxNum > 0) {
x=document.getElementsByName(inputFileID);
y=x.length;
if (y >= maxNum) {
alert('最多只允许添加' + maxNum + '个');
return false;
}
}**/
var parent=$G(parentID);//获取父元素
var div=document.createElement("div");//创建一个div容器tb用于包含input file
var x=parseInt(Math.random()*(80-1))+1;
var divName=inputFileID+x.toString();//随机div容器的名称
div.name=divName;
div.id=divName;
//创建input
var aElement=document.createElement("input");
aElement.name=inputFileID;
aElement.id=inputFileID+x+x;
aElement.type="text";//设置类型为file
aElement.className = "dynInputLen";
aElement.style.height="20";
aElement.style.width="220";
aElement.style.fontSize="15";
//创建select
var itemSelect = document.getElementsByName("itemSelect")[0];
var selElement=document.createElement("select");
selElement.name=itemSelect.name;
selElement.id=itemSelect.name+x;
for(var i=0;i<itemSelect.options.length;i++){
var value=itemSelect.options[i].value;
var text=itemSelect.options[i].text;
selElement.options.add(new Option(text,value));
}
selElement.style.width="70";
//动态加载onchange事件
if(window.addEventListener) // Mozilla, Netscape, Firefox
{
selElement.addEventListener('change', mychange,false);
}
else// IE
{
selElement.attachEvent('onchange',function(){
var selObj = $G(selElement.id);
var index = selObj.selectedIndex;
var str = selObj.options[index].text;
$G(aElement.id).value=str;
});
}
/**var delBtn=document.createElement("input");//再创建一个用于删除input file的Button
delBtn.type="button";
delBtn.value=" ";
delBtn.className = "btn_del";
delBtn.οnclick=function(){ removeInput(parentID,divName)};//为button设置tbonclick方法
**/
div.appendChild(aElement);//将input file加入div容器
div.appendChild(selElement);
//div.appendChild(delBtn);//将删除按钮加入div容器
parent.appendChild(div);//将div容器加入父元素
}
function changeItem(obj,param){
var index = obj.selectedIndex;
var str = obj.options[index].text;
$G(param).value=str;
}
</script>
</head>
<body>
<div align="left" id="dynadd" width="53%">
<input id="scheduleContent" name="scheduleContent" notnull="事项必须填写" style="height:20;width:220;font-size:15"/><select name="itemSelect" id="i1" style="width:70" οnchange="changeItem(this,'scheduleContent')"><option>开会</option> <option>addf</option> </select> <br>
<input id="scheduleContenta" name="scheduleContent" style="height:20;width:220;font-size:15"/><select name="itemSelect" id="i2" style="width:70" οnchange="changeItem(this,'scheduleContenta')"><option>开会</option><option>sdf</option></select>
</div>
<button style="position: top: 65px; right: 60px;cursor: hand; disabled:false;height:50;" onClick="_dynadd('dynadd','scheduleContent','3')">增加一行 </button>
</body>
</html>