在文件上传时实现图片剪切板个性化功能(2)
var sFileUpload = '\
<form id="form' + _sId + '" title="" enctype="multipart/form-data" action="<%=Globals.ApplicationPath %>/System/Club_ForumUploadImage.aspx?clubID=<%= SpacesContext.Current.ClubID %>" method="post" target="iframe_data">\
<input name="filePath" type="hidden" id="filePath' + _sId + '" />\
<input name="fileKey" type="hidden" value="' + _sId + '" />\
<input name="fileAction" id="fileAction' + _sId + '" value="" type="hidden" />\
<table width="180px" border="0" cellspacing="0" cellpadding="0" class="img_box">\
<tr>\
<td style="border:1px solid #000">\
<table width="100%" border="0" cellspacing="0" cellpadding="0">\
<tr style="background:#dee3e7">\
<td width="*" height="20"> <a href="javascript:addArticle(' + _sId + ');">插入图片</a></td>\
<td width="2"><img src="img/pic_box_sline.gif" width="2" height="12"></td>\
<td width="20" align="center"><a href="javascript:clearSelect(' + _sId + ');"><img src="<%=Globals.GetClubSkinPath() %>/images/del_btn.gif" width="10" height="10" border="0"></a></td>\
</tr>\
<tr>\
<td height="1" colspan="3" bgcolor="#787878"></td>\
</tr>\
<tr align="center" valign="middle" bgcolor="#ffffff">\
<td height="120" colspan="3" id="picShow' + _sId + '" style="background:url(\'\');"><span style="color:#7f7f7f">图片剪切板</span></td>\
</tr>\
</table>\
</td>\
</tr>\
<tr>\
<td height="1"></td>\
</tr>\
<tr>\
<td><input name="forumID" type="hidden" value="<%=SpacesContext.Current.ForumID %>" /><input name="fileContent" type="file" id="file' + _sId + '" type="file" style="width:auto!important;width:100%;border:1px solid #000; font-size:12px;" onchange="javascript:initUpload(this,' + _sId + ');" /> </td>\
</tr>\
</table>\
</form>\
其中
from+ID 表单ID
fileKey 表单序列号
filePath+key 文件的本地路径
picShow+ID 表单中的图片
file+ID 文件上传控件
当用户选择上传图片后, 触发initUpload事件,该事件用来把本地文件显示到picShow+ID中,单击发布文章后用js处理,先postFile文件,
function postFile(_sId){
var sId = 'form' + _sId;
if (exist(sId)) {
if ($(sId).title.length > 0 && seekUse(_sId)) {
$(sId).submit();
} else {
clearSelect(_sId);
postFile( ++_sId );
}
}else{
et.save();
var oForm=$('<%=PostForm.ClientID %>');
$('<%=btn_Post.ClientID %>').click();
}
}