js:

  $(document).ready(function () {

         //$('#creater').combobox({
         //    url: '/VMS.UI/BindData/ScheamData?type=26',
         //    dataType: 'json'

         //});

             $('#education').combobox({
                 url: '/VMS.UI/BindData/ScheamData?type=26',
                 dataType: 'json'
             });

             $('#job').combobox({
                 url: '/VMS.UI/BindData/ScheamData?type=24',
                 dataType: 'json',
                 value: '专职'
             });

             $('#station').combobox({
                 url: '/VMS.UI/BindData/ScheamData?type=29',
                 dataType: 'json'
             });

             $('#org').combotree({
                 url: '/VMS.UI/BindData/OrgData',
                 dataType: 'json',
                 idFiled: 'IID',
                 textFiled:'OrgName',
                 onLoadSuccess: function () {
                     $('#org').combotree('tree').tree("collapseAll");
                 },
                 onSelect: function (node) {
                     $('#dept').combobox({
                         url: '/VMS.UI/BindData/GetDepartments?deptID=' + node.id,
                         dataType: 'json',
                         valueField: 'IID',
                         textField: 'DeptName'
                     });
                 }
             });

         $(function () {
             $("#uploadpic").uploadPreview({
                 Img: "pic",
                 Width: 120,
                 Height: 120
             });
         });

         function formValidate() {
             var station = $('#station').combobox('isValid');
             var name = $('#name').validatebox('isValid');
             var cardNumber = $('#cardNumber').validatebox('isValid');
             var mobilePhone = $('#mobilePhone').numberbox('isValid');
             var org = $('#org').combotree('isValid');
             var dept = $('#dept').combobox('isValid');
             var drivingCertificate = $('input[name="DrivingCertificate"]').validatebox('isValid');
             if (!station) {
                 $('#station').combobox().next('span').find('input').focus()
                 return false;
             }
             if (!name) {
                 $('#name').focus();
                 return false;
             }
             if (!cardNumber) {
                 $('#cardNumber').focus()
                 return false;
             }
             if (!mobilePhone) {
                 $('#mobilePhone').focus()
                 return false;
             }
             if (!org) {
                 $('#org').combobox().next('span').find('input').focus()
                 return false;
             }
             if (!dept) {
                 $('#dept').combobox().next('span').find('input').focus()
                 return false;
             }
             if (!drivingCertificate) {
                 $('input[name="DrivingCertificate"]').focus()
             }
             return true;
         }

         $('#save').click(function () {
             if (formValidate()) {
                 $('#form_driverinfo').submit();
             }
         });

         $('#clear').click(function () {
             $.messager.confirm('确认对话框', '是否确定清空?', function (r) {
                 if (r) {
                     $('#form_driverinfo').form('reset');
                 }
             });
         });
     });

MVC:

 [HttpPost]
         public ActionResult AddVehicleDriver(VehicleDrivers driver)
         {
             if (driver.Picture != null)
             {
                 HttpPostedFileBase file = Request.Files["Picture"];
                 if (file != null)
                 {
                     driver.Picture = SaveImgAndGetPath(file);
                 }
             }
 }

  /// <summary>
         /// 保存图片并获取地址
         /// </summary>
         /// <param name="file">文件</param>
         /// <returns>返回路径</returns>
         private string SaveImgAndGetPath(HttpPostedFileBase file)
         {

             //设置文件名+获取文件扩展名
             string imgName = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999).ToString() + Path.GetExtension(file.FileName);

             // 生成要存档的 文件路径和文件名
             string serverPath = System.Web.HttpContext.Current.Server.MapPath("~");
             string imgFullPath = Path.Combine(serverPath, @"UploadImage\driverImg\", imgName);
             //string imgPath = Path.Combine(Server.MapPath("/UploadImage/driverImg/"), imgName);

             //上传服务器
             file.SaveAs(imgFullPath);

             string imgRelativePath = System.Web.HttpContext.Current.Request.ApplicationPath + @"\UploadImage\driverImg\" + string.Format("{0}", imgName);

             return imgRelativePath;
         }

jqueryExtends:

 jQuery.fn.extend({
     uploadPreview: function (opts) {
         var _self = this, _this = $(this);
         opts = jQuery.extend({
             Img: "ImgPr",
             Width: 100,
             Height: 100,
             ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],
             Callback: function () {
             }
         }, opts || {});
         _self.getObjectURL = function (file) {
             var url = null;
             if (window.createObjectURL != undefined) {
                 url = window.createObjectURL(file)
             } else if (window.URL != undefined) {
                 url = window.URL.createObjectURL(file)
             } else if (window.webkitURL != undefined) {
                 url = window.webkitURL.createObjectURL(file)
             }
             return url
         };
         _this.change(function () {
             if (this.value) {
                 if (!RegExp("\.(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
                     alert("选择文件错误,图片类型必须是" + opts.ImgType.join(",") + "中的一种");
                     this.value = "";
                     return false
                 }
                 if ($.browser.msie) {
                     try {
                         $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
                     } catch (e) {
                         var src = "";
                         var obj = $("#" + opts.Img);
                         var div = obj.parent("div")[0];
                         _self.select();
                         if (top != self) {
                             window.parent.document.body.focus()
                         } else {
                             _self.blur()
                         }
                         src = document.selection.createRange().text;
                         document.selection.empty();
                         obj.hide();
                         obj.parent("div").css({
                             'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)',
                             'width': opts.Width + 'px',
                             'height': opts.Height + 'px'
                         });
                         div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src
                     }
                 } else {
                     $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
                 }
                 opts.Callback()
             }
         })
     }
 });

上传预览 easyui部分控件获取focuse 表单验证的更多相关文章

  1. ux.plup.File plupload 集成 ux.plup.FileLis 批量上传预览

    //plupload 集成 Ext.define('ux.plup.File', { extend: 'Ext.form.field.Text', xtype: 'plupFile', alias: ...

  2. ASP.NET工作笔记之一:图片上传预览及无刷新上传

    转自:http://www.cnblogs.com/sibiyellow/archive/2012/04/27/jqueryformjs.html 最近项目里面涉及到无刷新上传图片的功能,其实也就是上 ...

  3. 模拟QQ心情图片上传预览

    出于安全性能的考虑,目前js端不支持获取本地图片进行预览,正好在做一款类似于QQ心情的发布框,找了不少jquery插件,没几个能满足需求,因此自己使用SWFuplad来实现这个图片上传预览. 先粘上以 ...

  4. 用html5文件api实现移动端图片上传&预览效果

    想要用h5在移动端实现图片上传&预览效果,首先要了解html5的文件api相关知识(所有api只列举本功能所需): 1.Blob对象  Blob表示原始二进制数据,Html5的file对象就继 ...

  5. 微信开发中使用微信JSSDK和使用URL.createObjectURL上传预览图片的不同处理对比

    在做微信公众号或者企业微信开发业务应用的时候,我们常常会涉及到图片预览.上传等的处理,往往业务需求不止一张图片,因此相对来说,需要考虑的全面一些,用户还需要对图片进行预览和相应的处理,在开始的时候我使 ...

  6. 兼容好的JS图片上传预览代码

    转 : http://www.codefans.net/articles/1395.shtml 兼容好的JS图片上传预览代码 (谷歌,IE11) <html xmlns="http:/ ...

  7. PHP WAMP 文件上传 及 简单的上传预览

    ...... 使用特殊的表单类型file, 主(上传)页面: <form action="chuli.php" method="post" enctype ...

  8. 单图上传预览(uploadpreview )

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. Jquery图片上传预览效果

    uploadPreview.js jQuery.fn.extend({ uploadPreview: function (opts) { var _self = this, _this = $(thi ...

随机推荐

  1. jQuery动态绑定

    一.原始需求 在实际项目的时候,遇到了一个问题,就是通过JS动态生成的元素,无法触发JS事件. 原始的JS代码: $(function () { $(".original").cl ...

  2. ecos的app处理类

    get 获取指定app的对象实例 参数 $app_name 返回指定app name的app类实例 app::get('desktop') render 获取base_render类的实例 base_ ...

  3. win7 以管理员身份运行cmd, windows services 的创建和删除

    以 http 协议访问svn repository 搭建可用http访问的svn(windows) http://blog.csdn.net/yangyangrenren/article/detail ...

  4. 使用bootstrap响应式布局——手机屏幕中横向滚动显示标签页选项

    导航栏到小屏幕的时候,我们的处理办法是隐藏为一个按钮.可是选项卡的标签页部分,我们的处理办法是加一个水平滚动条.但是加水平滚动条需要解决一个问题,就是宽度的问题,如果不设置宽度,他就会根据屏幕大小自适 ...

  5. 已有 JS 模块化和打包方案收集

    模块化方案 RequireJS AMD 方案, 常用的 define 语法, 异步加载模块, 目前很多支持: 官网 http://requirejs.org/ Github https://githu ...

  6. CodeForces 617E XOR and Favorite Number

    莫队算法. #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> ...

  7. 19、手把手教你Extjs5(十九)模块Grid的其他功能的设想

    经过对自定义模块和Grid的设计和编码,现在已经能对一个有配置信息的模块来生成界面并进行一些简单的CURD操作.由于这是一个全解释性的前台的架构,因此你想到的任何新主意都可以放到所有的模块中. 比如对 ...

  8. LPC1788的ADC和DAC使用

    #ifndef __ADC1_H_ #define __ADC1_H_ #include "common.h" #include "delay.h" void ...

  9. java实现——009Fibonacci数列

    1.循环 public class T009 { public static void main(String[] args){ System.out.println(fibonacci(3)); } ...

  10. sql server 2008 学习笔记

    sql server 2008 删除已有的实例 想从setup.exe中区卸载,没找到. 原来还是要从控制面板中卸载,卸载Microsoft SQL Server 2008 卸载界面会提示让你选择要删 ...