-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
161 lines (76 loc) · 3.54 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<script type="text/javascript" src="Public/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
//限制文件数
var mflFileMaxCount = 5;
var mflFileCount = 0;
//限制文件类型
var mflCouldUserTypes = "|.jpeg|.jpg|.gif|.png|.bmp|";
function AddFile(obj) {
var fileName = obj.value;
if (mflFileCount >= mflFileMaxCount) {
window.alert("信息提示:系统设置,最多只能同时上传[" + mflFileMaxCount + "]个文件.");
return;
}
if ($.trim(fileName) == "") {
//用户没有选择文件
return;
}
if($("#hdFileName").attr("value").length>1)
{
var arr = $("#hdFileName").attr("value").split(",");
for(var i=0; i<arr.length;i++)
{
if(arr[i]==fileName){
window.alert("该文件已经存在任务列表中!");
return;
}
}
}
$("#hdFileName").val($("#hdFileName").attr("value")+","+fileName);
var type = fileName.substring(fileName.lastIndexOf("."));
type = type.toLowerCase(); //将字符串换成小写
var sFileName = fileName.substring(fileName.lastIndexOf("\\"));
var newFileLoadTmp = "<input type='file' name='mflFileUpload" + (mflFileCount + 1) + "' id='mflFileUpload" + (mflFileCount + 1) + "' onchange='AddFile(this)' class='mflFileUploadCss' />"
var newLiFile = "<li><span class='FileNameStyle'>" + sFileName + "</span> <img src='http://blog.163.com/thylx133@126/blog/../images/ac_02.jpg' onclick='mflRemoveFile(this)' /></li>";
if ($.trim(type) == "" || $.trim(sFileName) == "") {
//用户没有选择文件
return;
}
if (mflCouldUserTypes.indexOf("|" + type + "|") != -1) {
$(obj).css("display","none");
$(".mflLeft_FileUpload").append(newFileLoadTmp);
$(".mflRightOlFiles").append(newLiFile);
mflFileCount += 1;
$(".mflFileCountMsg").html("已选文件数:"+mflFileCount);
}
else {
window.alert("信息提示:文件类型不正确。");
}
}
function mflRemoveFile(obj) {
if (confirm("信息提示:确定移除该文件?")) {
var innerHtml = $(obj).parent().html();
var itemIndex = 0;
for (itemIndex = 0; itemIndex < $(".mflRightOlFiles li").length; itemIndex++) {
if ($(".mflRightOlFiles li").eq(itemIndex).html() == innerHtml) {
break;
}
}
$(".mflRightOlFiles li").eq(itemIndex).remove();
$(".mflLeft_FileUpload input").eq(itemIndex).remove();
mflFileCount -= 1;
$(".mflFileCountMsg").html("已选文件数:" + mflFileCount);
}
}
</script>
<style type="text/css">
.mflFileUploadCss { width:83px; filter:alpha(opacity=0); opacity:0; }
.mflLeft_FileUpload{ background-image:url("../images/btn_look.jpg"); width:83px; overflow:hidden; }
.mflLeft_AddFileUpload { background-image:url("../images/btn_addPic.jpg"); }
.mflRightOlFiles{ padding-left:5px;}
</style>
<div class="mflLeft_FileUpload" style="float:left;">
<asp:FileUpload ID="FileUpload1" onchange="AddFile(this)" CssClass="mflFileUploadCss" runat="server" /> </div> (文件类型:jpeg ; jpg ; gif ; png:bmp)
<ul class="mflRightOlFiles">
</ul>
<span class="mflFileCountMsg"></span>