⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadfile.ascx

📁 jsp实现的网上购物系统
💻 ASCX
字号:
<%@ Control CodeBehind="UploadFile.ascx.cs" Language="c#" AutoEventWireup="false" Inherits="JiSuShop.Web.Admin.Ascx.UploadFile" %>
<%@import namespace="JiSuShop.Components"%>
<%@import namespace="System.Drawing"%>
<link type="text/css" rel="stylesheet" href="images/default.Css">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
	<tr>
		<td colspan="2" style="border:1px solid #CCC">
			上传<input type="text" size="2" value="5" id="fileCount">个文件
			<input type="button" class="C_input" onclick="Option()" value="确定">&nbsp;&nbsp;
			<input type="button" class="C_input" onclick="Option(0)" value="添加文件"> 
			<input type="button" class="C_input" onclick="Option(1)" value="删除文件">
			<asp:Button CssClass="C_input02" id="Button1" runat="server" Text="上传文件"></asp:Button>
			上传到 <asp:DropDownList Runat=server ID=dirs></asp:DropDownList>
		</td>
	</tr>
	<tr>
		<td width="500" valign=top>
		<br>
			<span id="area">
				<input type="file" runat="server" id="files" size="50" /></span><!--span两端不能有空格-->
		</td>
		<td align=right valign=top>
			<br>
			<div id="divView" style="padding:3px;border: 1px solid #CCC;width:10px;heigth:10px;">
				<img src="" width=120 height=73 id="view" onerror="this.style.display = 'none';document.getElementById('divView').style.display = 'none'"></div>
		</td>
	</tr>
</table>


<script>
var max = 15
var maxImageSize = 130;
var currentName = 0;
var area = document.getElementById("area");
var view = document.getElementById("view");
var divView = document.getElementById("divView");
function Option(type)
{
	
	if(type == "0")
	{//添加一下文件
		add();
	}
	if(type == "1" && area.childNodes.length > 1)
	{
		remove();
	}
	if(type == null)
	{
		var cou = document.getElementById("fileCount");
		cou.value = GetNumber(cou.value.replace(" ",""));
		if(cou.value == "")
		{
			alert("请输入要上传文件的数量!");
			cou.focus();
			return;
		}
		var num = parseInt(cou.value);
		if(num.toString() == "NaN")
		{
			alert("在这里只能输入上传文件数量!");
			cou.value = "1".toString();
			cou.focus();
			return;
		}
		if(num > max)
		{
			cou.value = max.toString();
			num = max;
		}
		if(num < 0)
		{
			cou.value = "1".toString();
			num = 1;
		}
		var num1 = area.childNodes.length / 2 + 0.5;
		if(num > num1)//要上传的文件大于当前显示的文件
		{
			num = num - num1;
			for(var i = 0;i < num;i++)
			{
				add(0);
			}
		}
		else
		{
			num = num1 - num;
			for(var i = 0;i < num;i++)
			{
				remove();
			}
		}
	}
}
function add(noChange)
{
	if(area.childNodes.length / 2 + 1 >= max)return;
	var o = GetFile();
	var b = GetButton(o);
	if(noChange != 0)
	{
		var cou = document.getElementById("fileCount");
		cou.value = parseInt(GetNumber(cou.value.replace(" ",""))) + 1;
	}
	//alert();
	area.appendChild(o);
	area.appendChild(b);
}
function GetButton(o)
{
	var ne = document.createElement("button");
	ne.value = "删除";
	ne.input = o;
	ne.onclick = deleteOn;
	return ne;
}
function deleteOn()
{
	var b = event.srcElement;
	var o = b.input;
	remove(b);
	remove(o);
}
function remove(o)
{
	if(o == null)
	{
		o = GetLastChild(area);
		area.removeChild(o);
		o = GetLastChild(area);
		
	}
	if(o.tagName == "INPUT")
	{
		var cou = document.getElementById("fileCount");
		cou.value = parseInt(GetNumber(cou.value.replace(" ",""))) - 1;
	}
	area.removeChild(o);
}
///
function IsNumber(str)
{
	if(str.length == 0)return false;
	var reg
	reg = new RegExp("^([-+]?[0-9]+(\.?[0-9]+)?)$","");
	return (reg.test(str));
}
//把123转成123
function GetNumber(str)
{
	var re = "";
	var num;
	for(var i = 0;i <str.length;i++)
	{
		num = str.charCodeAt(i);
		if(num >= 65296 && num <= 65305)
		{
			
			num -= 65248;
			
		}
		
		re += String.fromCharCode(num);
	}
	return re;
}
function GetLastChild(o)
{
	var re = o.childNodes[o.childNodes.length - 1];
	return re;
}
var index = 0;
function GetFile()
{
	var ne = document.createElement("input");
	ne.size = 50;
	ne.type = "file";
	ne.onfocus = ViewImg
	ne.onblur = ViewImgEnd
	ne.name = "files1" + currentName;
	ne.id = "list" + index;
	index++;
	currentName ++;
	return ne;
}
function ViewImg()
{
	var o = event.srcElement;
	if(o.isView == null || o.isView == false)
	{
		o.isView = true;
		var temp = document.createElement("img");
		temp.src = o.value;
		view.style.display = '';
		divView.style.display = '';
		var s = new Size(temp.width,temp.height);
		s = GetSizeForMax(s,maxImageSize);
		temp.width = s.Width;
		temp.height = s.Height;
		view.width = temp.width;
		view.height = temp.height;
		view.src = temp.src;
		//alert(view.width + " " + view.height);
	}
}
function Size(width,height)
{
	this.Width = width;
	this.Height = height;
}
function GetSizeForMax(s,max)
{
	var m = 0
	if(s.Width > s.Height)
	{
		m = s.Width ;
	}
	else
	{
		m = s.Height;
	}
	
	m = m / max;
	
	s.Height = (s.Height / m);
	s.Width = (s.Width / m);
	return s;
}
var d = new Size(500,800);
d = GetSizeForMax(d,400);
function ViewImgEnd()
{
	var o = event.srcElement;
	o.isView = false;
}
area.childNodes[0].onfocus = ViewImg
area.childNodes[0].onblur = ViewImgEnd
Option();
var de = document.getElementById("fileCount")
if(de != null)
{
	de.value = "5";
}
</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -