动态添加删除表单
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>
读取文件夹中某类型的图片
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>
相关文章推荐
- jquery + php动态添加删除表单的方法
- jQuery动态添加及删除表单上传元素的方法(附demo源码下载)
- jQuery动态添加及删除表单上传元素的方法(附demo源码下载)
- js动态添加删除表单
- Angular4实现动态添加删除表单输入框功能
- Angular4实现动态添加删除表单输入框功能
- 第13篇:Angular-表单动态添加删除
- jQuery可以计算的表单,包括单选改变价格,select改变价格,动态添加删除行计算
- 动态的添加、删除表单
- JavaScript 动态删除/添加HTML表单元素(可以浏览本地文件)
- jQuery实现表单动态添加与删除数据操作示例
- jquery动态添加表单删除表单
- jQuery - 动态添加、删除form表单项(附:新增项数据无法提交问题解决)
- ViewPager动态添加、删除Fragment,且提供红色小圆球指示当前位置
- JavaScript动态改变HTML页面元素例如添加或删除
- ViewPager+Fragment实现Tabhost,动态添加删除Fragment,可供第三方使用的类库
- JS动态添加删除表格行
- 在Vue组件上动态添加和删除属性
- Android中动态添加╱删除的Spinner菜单 — ArrayList与Widget的依赖性
- 使用JQueryUI + FreeMarker 实现Div动态DIalog添加和删除