求助一个js上传文件的怎么写? 求助一个js上传文件的怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 js 用户自定义多文件上传代码<!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=gb2312" /><title>批量上传</title><script type="text/javascript">var attachname = "attach";var i=1;function addInput(){if(i<10){var attach = attachname + i ;if(createInput(attach))i=i+1;}} function deleteInput(){if(i>1){i=i-1;if(!removeInput())i=i+1;}} function createInput(nm){ var aElement=document.createElement("div"); var html = "附件("+i+")<input type="file" id="FileUpload" + i + "" name="FileUpload" + i + "" title="选择图片" size="45" onchange="javascript:showphoto();"><br />" + "<img alt="js 用户自定义多文件上传代码" width="0" id="Image" + i + "" name="Image" + i + "" src="" title="图片预览" style="margin-left: 55px;" >";aElement.innerHTML=html;//aElement.value="thanks"; //aElement.onclick=Function("asdf()"); if(document.getElementById("upload").appendChild(aElement) == null)return false;return true;} function removeInput(nm){var aElement = document.getElementById("upload");if(aElement.removeChild(aElement.lastChild) == null)return false;return true; }function showphoto(){ var re=/.(jpg|jpeg|JPG|JPEG)$/; var x=document.getElementById('upload').getElementsByTagName('input'); for(r=0;r<x.length;r++){ if ((!re.test(document.getElementById("FileUpload"+[r+1]).value)) & (document.getElementById("FileUpload"+[r+1]).value!="")) { alert("只允许上传jpg文件!"); document.getElementById("FileUpload"+[r+1]).outerHTML=document.getElementById("FileUpload"+[r+1]).outerHTML.replace(/value=w/g,''); document.getElementById("Image"+[r+1]).style.width="0px"; document.getElementById("Image"+[r+1]).src=""; }else if (document.getElementById("FileUpload"+[r+1]).value!="") { document.getElementById("Image"+[r+1]).style.width="100px"; document.getElementById("Image"+[r+1]).src=document.getElementById("FileUpload"+[r+1]).value; }}}function newInput(){ var x=document.getElementById('upload').getElementsByTagName('img'); for(r=0;r<9;r++){ addInput(); x[r].width="100"; x[r].src=document.getElementById("smPicture").value.replace("sm","sm"+[r+1]); //x[r].onerror=function(){deleteInput()}; }}</script><script type="text/javascript">onload=function(){newInput();}</script></head><body><input type="button" name="button" value="添加附件" onclick="addInput()"><input type="button" name="button" value="删除附件" onclick="deleteInput()"><span id="upload"></span><input name="smPicture" type="hidden" id="smPicture" value='http://222.70.206.26/img/5/5000011_sm.jpg'></body></html> 通过 form 标签,或者 flash 我的是只有一个路径,能取到这个文件,但是FileUpload,这样我要怎么保存呢?我要做的效果就是跟我们平时另保存文件一样的。请各位帮帮忙 求教下正则的问题 表格某行单元格中文本框的值? 请问call(),apply()的具体用法 麻烦大家帮我帮代码改哈,我希望回车后是换行 对联广告不能够定位,请指教 救命啊!!!请高手告诉我怎么判断鼠标在一个页面上是静止不动的? 如果得知当前窗口是普通窗口还是模式窗口?? 关于UId的问题.请指教 如何关闭IE的快捷键(CTRL+N)最好效果能象禁止鼠标右键一样! java script的一个问题?? 求教JQuery ui插件的一个关于拖动的问题 jquery 如何查找两个元素之间的元素
js 用户自定义多文件上传代码
<!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=gb2312" />
<title>批量上传</title>
<script type="text/javascript">
var attachname = "attach";
var i=1;
function addInput(){
if(i<10){
var attach = attachname + i ;
if(createInput(attach))
i=i+1;
}
}
function deleteInput(){
if(i>1){
i=i-1;
if(!removeInput())
i=i+1;
}
}
function createInput(nm){
var aElement=document.createElement("div");
var html = "附件("+i+")<input type="file" id="FileUpload"
+ i + "" name="FileUpload"
+ i + "" title="选择图片" size="45" onchange="javascript:showphoto();"><br />"
+ "<img alt="js 用户自定义多文件上传代码" width="0" id="Image"
+ i + "" name="Image"
+ i + "" src="" title="图片预览" style="margin-left: 55px;" >";
aElement.innerHTML=html;
//aElement.value="thanks";
//aElement.onclick=Function("asdf()");
if(document.getElementById("upload").appendChild(aElement) == null)
return false;
return true;
}
function removeInput(nm){
var aElement = document.getElementById("upload");
if(aElement.removeChild(aElement.lastChild) == null)
return false;
return true;
}
function showphoto(){
var re=/.(jpg|jpeg|JPG|JPEG)$/;
var x=document.getElementById('upload').getElementsByTagName('input');
for(r=0;r<x.length;r++){
if ((!re.test(document.getElementById("FileUpload"+[r+1]).value)) & (document.getElementById("FileUpload"+[r+1]).value!=""))
{
alert("只允许上传jpg文件!");
document.getElementById("FileUpload"+[r+1]).outerHTML=document.getElementById("FileUpload"+[r+1]).outerHTML.replace(/value=w/g,'');
document.getElementById("Image"+[r+1]).style.width="0px";
document.getElementById("Image"+[r+1]).src="";
}else if (document.getElementById("FileUpload"+[r+1]).value!="")
{
document.getElementById("Image"+[r+1]).style.width="100px";
document.getElementById("Image"+[r+1]).src=document.getElementById("FileUpload"+[r+1]).value;
}
}
}
function newInput(){
var x=document.getElementById('upload').getElementsByTagName('img');
for(r=0;r<9;r++){
addInput();
x[r].width="100";
x[r].src=document.getElementById("smPicture").value.replace("sm","sm"+[r+1]);
//x[r].onerror=function(){deleteInput()};
}
}
</script>
<script type="text/javascript">
onload=function(){
newInput();
}
</script>
</head>
<body>
<input type="button" name="button" value="添加附件" onclick="addInput()">
<input type="button" name="button" value="删除附件" onclick="deleteInput()">
<span id="upload"></span>
<input name="smPicture" type="hidden" id="smPicture" value='http://222.70.206.26/img/5/5000011_sm.jpg'>
</body>
</html>