您的位置:首页 > Web前端 > HTML

动态添加删除表单

2009-09-14 10:16 330 查看
//
读取文件夹中某类型的图片

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>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息