’这是上传照片页面
Dim e As RequestEventArgs = args(0) '上传照片
Dim wb As New weui
wb.Title = "123456"
If e.PostValues.Count = 0 Then
wb.AddTopTips("","toptip1","") '用于显示动态错误提示
wb.AddPageTitle("","pageheader","123456","")
wb.AddForm("","form1","valid_images.htm")
With wb.AddInputGroup("form1","ipg1","展示照(请选择清晰靓照,1张即可)") '文件上传(1个)
With.AddUploader("up1","",False)
.AllowDelete = True '允许用户删除图片
.ScaleWidth = 400 '自动压缩图片宽度为400个像素,高度等比例压缩
End With
End With
With wb.AddInputGroup("form1","ipg22","生活照(非必须上传)") '带图片浏览的文件上传(最少4个) 选择3张以上靓照
With.AddUploader("up4","",True) 'True表示允许一次上传多个文件
.AllowDelete = True '允许删除
.Incremental = True '允许 重复选择文件或连续拍照
.ScaleWidth = 400 '自动压缩图片宽度为400个像素,高度等比例压缩
End With
End With
With wb.AddButtonGroup("form1","btg1",True)
.Add("btn1", "提交", "button").Attribute= "onclick='validit_images()'" '调用js函数上传
End With
wb.AddToast("","tst1", "正在上传",1)
wb.AddToast("","tst2", "上传成功",0)
wb.AddToast("","tst3", "上传失败",0).Icon= "warn"
wb.AppendHTML("<script src='./lib/ajaxform_images.js'></script>") '引入脚本文件
e.WriteString(wb.Build) '生成网页
End If
’这是处理照片的js,已经能够实现判断照片格式和照片数量,可否在下面的js代码中
’希望js增加功能:1.判断照片的宽度小于400,提示照片分辨率太小;2.照片宽度<高度,提示请上传竖着拍的照片。
function validit_images(){
var v1 = document.getElementById("up1_thumbnails").getElementsByTagName("li").length;
var v2 = document.getElementById("up4_thumbnails").getElementsByTagName("li").length;
//alert(v1 + " " + v2);
var frm = document.getElementById("form1");
var frmdata = new FormData(frm);
if (frm.incremental) {
var fluds = frm.getElementsByClassName("weui_uploader_input");
for (var idx = 0; idx < fluds.length; idx++) {
var files = fluds[idx].Files;
if (files) {
for (var i = 0; i < files.length; i++) {
//alert(files[i].blobFile);
var fln = files[i].blobFile
if (typeof(fln) == "undefined") {
//alert("照片格式不正确");
showTopTips("toptip1","照片格式不正确!",2000);
return false;
}
fln = fln.substring(fln.lastIndexOf(".") + 1).toLowerCase();
switch (fln) {
case "jpg":
case "jpeg":
//case "png":
//case "gif":
case "bmp":
break;
default:
//alert("照片格式不正确");
showTopTips("toptip1","照片格式不正确!",2000);
return false;
}
}
}
}
}
if(v1 < 1){
showTopTips("toptip1","请选择1张展示照上传!",2000);
return false;
}
if(v1 > 1){
showTopTips("toptip1","展示照只可以上传1张!",2000);
return false;
}
if(v2 > 0){
if(v2 < 3){
showTopTips("toptip1","请选择3张以上生活照上传!",2000);
return false;
}
}
if(v2 > 6){
showTopTips("toptip1","生活照最多可以上传6张!",2000);
return false;
}
show("tst1",2000);
var result = submitAjaxForm('form1','afterSubmit');
}
function afterSubmit(result){
hide("tst1");
if (result=='OK') {
show("tst2");
location="success.htm";
}
else{
show("tst3",2000);
}
}
[此贴子已经被作者于2018/1/5 8:56:11编辑过]