动态添加删除表单

来源:互联网 发布:sqlserver 2008 安装 编辑:程序博客网 时间:2024/05/01 04:15

//读取文件夹中某类型的图片

using System.IO;

        DirectoryInfo imagesfile = new DirectoryInfo(Server.MapPath("~/image"));

        FileInfo[] fileinfo = imagesfile.GetFiles("*.jpg");

        foreach (FileInfo fi in fileinfo)

        {

            strpic += "<img src=/"../image/" + fi.Name + "/" />";

        }

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function $(obj)
{
    return document.getElementById(obj);
}
function cloneObj(oClone, oParent, count)
{
   if(oParent.childNodes.length < count)
   {
      var newNode = oClone.cloneNode(true);  //复制表单
      oParent.appendChild(newNode);
      return newNode;
   }
   return false;
}

function delObj(oParent, count)
{
   if(oParent.childNodes.length > count)
   {
      oParent.removeChild(oParent.lastChild);  //删除最后一个
      return true;
   }
   return false;
}

function clonePoll(maxpoll, arrayinput, arraydiv)
{
   for(c=0;c<arrayinput.length;c++)
   {
      var newNode = cloneObj($(arrayinput[c]), $(arraydiv[c]) , parseInt(maxpoll) + 1);
      if(!newNode)
      {
         alert("时间项不能多于 " + maxpoll + " 个");
      }
      var inputs = newNode.getElementsByTagName("input");
      for(i in inputs)
      {
         inputs[i].value = "";
         if(inputs[i].name == arraydiv[c])
         {
            inputs[i].id = arraydiv[c];
         }
      }
   }
}
</script>
</head>

<body>
<div id="polloptions">
     <div id="divPollItem" style="float: left;">
          <input type="text" size="30" id="pollitemid" name="pollitemid" maxlength="30" onfocus=" " />
</div>
</div>

<div id="polloptions2" style="float: left;">
     <div id="divPollItem2">
          <input type="text" size="30" id="pollitemid2" name="pollitemid2" maxlength="30" onfocus=" " />
          <input type="file" />
</div>
</div>
<input name="button" type="button" onclick="clonePoll('20',['divPollItem','divPollItem2'],['polloptions','polloptions2'])" value="增加时间项" />
<input name="button" onclick="if(!delObj(document.getElementById('polloptions'),1) || !delObj(document.getElementById('polloptions2'),1)){alert('时间项不能少于1个');}" type="button" value="删除时间项" />
</body>
</html>

 

原创粉丝点击