六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 68|回复: 0

Javascript动态创建控件

[复制链接]

升级  64.67%

45

主题

45

主题

45

主题

秀才

Rank: 2

积分
147
 楼主| 发表于 2013-2-7 18:24:20 | 显示全部楼层 |阅读模式
 
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee;"><html>

<head>

<title></title>
<script language="javascript" type="text/javascript">
function createElement(tagName, type)
{
   
var element = null;
   
try
   
{
      element 
= document.createElement('<+ tagName + ' name="'+name+'" />');
      element.type 
= type;
      element.value 
= value;
   }

   
catch (e)
   
{
   }

   
if ( ! element)
   
{
      element 
= document.createElement(tagName);
      element.setAttribute(
"type", type);
   }

   
return element;
}



function add()
{
    
var input1 = createElement("input","file");
    
var br = document.createElement("<br />");
    
var files = document.getElementById("files");
    files.appendChild(br);
    files.appendChild(input1);
}

</script>
</head>

<body>
<input type="button" value="add" onclick="add();"/>
<div id="files">
<input type="file"/>
</div>
</body>

</html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表