以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 代码合并问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=98621) |
-- 作者:zhangjian222200 -- 发布时间:2017/4/2 16:05:00 -- 代码合并问题 function submitForm(){ show("tst1",2000); var result = submitAjaxForm(\'form1\',\'afterSubmit\'); } function afterSubmit(result){ hide("tst1"); if (result==\'OK\') { show("tst2"); location="upload.htm"; } else{ show("tst3",2000); } } 将下面这段代码合并到上面代码里, 上面代码是:移动文档“增强Uploader”里 下面代码是:能够成功执行toptip提示 我自己弄了下,问题用粉色写在2~4楼,代码合并写在2楼,页面代码写在3楼 function validit_images(){ var v1 = document.getElementById("up1").files.length; var v2 = document.getElementById("up4").files.length; if(v1 < 1){ showTopTips("toptip1","请选择1张展示照上传",2000); return false; } if(v2 < 4){ showTopTips("toptip1","请选择4张以上生活照上传",2000); return false; } return true; }
[此贴子已经被作者于2017/4/2 18:36:36编辑过]
|
-- 作者:zhangjian222200 -- 发布时间:2017/4/2 17:42:00 -- 我是这样合并的,当没有选择图片时,点击页面上传,toptip没有显示,直接跳转到success.htm,提示 .NET Framework 版本:2.0.50727.3655 Foxtable 版本:2017.3.18.1 错误所在事件:自定义函数valid_images 详细错误信息: 调用的目标发生了异常。 索引超出了数组界限。 js合并如下: function submitForm(){ show("tst1",2000); var result1 = submitAjaxForm(\'form1\',\'validit_images\'); var result2 = submitAjaxForm(\'form1\',\'afterSubmit\'); } function afterSubmit(result2){ hide("tst1"); if (result2==\'OK\') { show("tst2"); location="upload.htm"; } else{ show("tst3",2000); } } function validit_images(){ var v1 = document.getElementById("up1").files.length; var v2 = document.getElementById("up4").files.length; if(v1 < 1){ showTopTips("toptip1","请选择1张展示照上传",2000); return false; } if(v2 < 4){ showTopTips("toptip1","请选择4张以上生活照上传",2000); return false; } return true; } 页面代码在3楼
[此贴子已经被作者于2017/4/2 17:59:32编辑过]
|
-- 作者:zhangjian222200 -- 发布时间:2017/4/2 17:44:00 -- 这是内部函数images代码: Dim e As RequestEventArgs = args(0) \'注册第7页,上传照片 Select Case e.Path Case "images.htm" Dim wb As New weui If e.PostValues.Count = 0 Then wb.AddTopTips("","toptip1","") \'用于显示动态错误提示 wb.AddPageTitle("","pageheader","***","******") wb.AddForm("","form1","valid_images.htm").Attri-bute="on-submit=\'re-turn validit_images()\'" With wb.AddInputGroup("form1","ipg1","展示照(选择1张靓照即可)") \'文件上传(1个) With .AddUploader("up1","",False) .AllowDelete = True \'允许删除 .Incremental = True \'允许 重复选择文件或连续拍照 .ScaleWidth = 400 \'自动压缩图片宽度为400个像素,高度等比例压缩 End With End With With wb.AddInputGroup("form1","ipg22","生活照(选择4张以上靓照)") \'带图片浏览的文件上传(最少4个) With .AddUploader("up4","",True) \'True表示允许一次上传多个文件 .AllowDelete = True \'允许删除 .Incremental = True \'允许 重复选择文件或连续拍照 .ScaleWidth = 400 \'自动压缩图片宽度为400个像素,高度等比例压缩 End With End With With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "提交", "submit") 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 End Select 这是内部函数valid_images代码: Dim e As RequestEventArgs = args(0) \'验证页面(照片) Select Case e.Path Case "valid_images.htm" Dim wb As New weui Dim drbianh As String = e.Cookies("drbianhao") \'为cookie传递数据 Dim NewName As String \'msgbox(drbianh) Dim dr As DataRow = DataTables("会员资料").sqlFind("会员编号 = \'" & drbianh & "\'") If dr IsNot Nothing Then \'测试代码:msgbox(e.PostValues("isr")) For Each key As String In e.Files.Keys If key = "up1" Then For Each fln As String In e.Files(key) \'msgbox(0) Dim ext As String = fln.Split(".")(1) \'NewName = Format(Date.Now, "yyyyMMddHHmmssffffff") & "." & ext NewName = Format(Date.Now, "yyyyMMddHHmmssffffff") & Rand.Next(10000) & "." & ext e.SaveFile(key, fln, ProjectPath & "Attachments\\" & NewName) \'dr("展示照") = iif(dr.IsNull("展示照"), "", vbcrlf) & NewName dr("展示照") &= iif(dr.IsNull("展示照"), "", vbcrlf) & NewName Next End If Next For Each key1 As String In e.Files.Keys If key1 = "up4" Then For Each fln1 As String In e.Files(key1) \'msgbox(1) Dim ext1 As String = fln1.Split(".")(1) \'NewName = Format(Date.Now, "yyyyMMddHHmmssffffff") & "." & ext1 NewName = Format(Date.Now, "yyyyMMddHHmmssffffff") & Rand.Next(10000) & "." & ext1 e.SaveFile(key1, fln1, ProjectPath & "Attachments\\" & NewName) \'dr("生活照") = iif(dr.IsNull("生活照"), "", vbcrlf) & NewName dr("生活照") &= iif(dr.IsNull("生活照"), "", vbcrlf) & NewName Next End If Next dr.save() \'保存 End If wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面:/success.htm e.WriteString(wb.Build) \'生成网页 End Select [此贴子已经被作者于2017/4/2 20:55:24编辑过]
|
-- 作者:zhangjian222200 -- 发布时间:2017/4/2 18:10:00 -- 另外,在有照片上传时,Attachments内,有每张照片都有2张 [此贴子已经被作者于2017/4/2 18:37:05编辑过]
|
-- 作者:有点色 -- 发布时间:2017/4/2 19:27:00 -- 1、不要提交两次
var result1 = submitAjaxForm(\'form1\',\'validit_images\'); var result2 = submitAjaxForm(\'form1\',\'afterSubmit\');
如果要调用函数,直接写 validit_images();
2、看1、先执行js验证,再提交
If(validit_images()) {
var result2 = submitAjaxForm(\'form1\',\'afterSubmit\');
}
|
-- 作者:zhangjian222200 -- 发布时间:2017/4/2 20:55:00 -- 3楼内部函数images代码,增加3楼粉色部分,不能正确执行(选与不选照片,均提示:请选择1张展示照上传),问3楼代码如何修改,才能正确提示下述代码的toptip? js代码如下:
function validit_images(){ var v1 = document.getElementById("up1").files.length; var v2 = document.getElementById("up4").files.length; if(v1 < 1){ showTopTips("toptip1","请选择1张展示照上传",2000); return false; } if(v2 < 4){ showTopTips("toptip1","请选择4张以上生活照上传",2000); return false; } return true; } 并且,增加粉色代码后,界面选择图片后,+号右侧应该出现的数字也不见了 [此贴子已经被作者于2017/4/2 21:19:01编辑过]
|
-- 作者:有点蓝 -- 发布时间:2017/4/4 11:42:00 -- 加了Incremental属性的原因,这种情况无法通过正常的files.length获取文件数量 [此贴子已经被作者于2017/4/4 11:45:49编辑过]
|
-- 作者:有点蓝 -- 发布时间:2017/4/4 11:49:00 -- 变通一下, up1去掉Incremental属性 up4的数量这样判断 function validit_images(){ var v1 = document.getElementById("up1").files.length; var v2 = document.getElementById("up4_thumbnails").getElementsByTagName("li").length; if(v1 < 1){ showTopTips("toptip1","请选择1张展示照上传",2000); return false; } if(v2 < 4){ showTopTips("toptip1","请选择4张以上生活照上传",2000); return false; } return true; } |