上传预览 easyui部分控件获取focuse 表单验证
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 表单验证的更多相关文章
- ux.plup.File plupload 集成 ux.plup.FileLis 批量上传预览
//plupload 集成 Ext.define('ux.plup.File', { extend: 'Ext.form.field.Text', xtype: 'plupFile', alias: ...
- ASP.NET工作笔记之一:图片上传预览及无刷新上传
转自:http://www.cnblogs.com/sibiyellow/archive/2012/04/27/jqueryformjs.html 最近项目里面涉及到无刷新上传图片的功能,其实也就是上 ...
- 模拟QQ心情图片上传预览
出于安全性能的考虑,目前js端不支持获取本地图片进行预览,正好在做一款类似于QQ心情的发布框,找了不少jquery插件,没几个能满足需求,因此自己使用SWFuplad来实现这个图片上传预览. 先粘上以 ...
- 用html5文件api实现移动端图片上传&预览效果
想要用h5在移动端实现图片上传&预览效果,首先要了解html5的文件api相关知识(所有api只列举本功能所需): 1.Blob对象 Blob表示原始二进制数据,Html5的file对象就继 ...
- 微信开发中使用微信JSSDK和使用URL.createObjectURL上传预览图片的不同处理对比
在做微信公众号或者企业微信开发业务应用的时候,我们常常会涉及到图片预览.上传等的处理,往往业务需求不止一张图片,因此相对来说,需要考虑的全面一些,用户还需要对图片进行预览和相应的处理,在开始的时候我使 ...
- 兼容好的JS图片上传预览代码
转 : http://www.codefans.net/articles/1395.shtml 兼容好的JS图片上传预览代码 (谷歌,IE11) <html xmlns="http:/ ...
- PHP WAMP 文件上传 及 简单的上传预览
...... 使用特殊的表单类型file, 主(上传)页面: <form action="chuli.php" method="post" enctype ...
- 单图上传预览(uploadpreview )
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Jquery图片上传预览效果
uploadPreview.js jQuery.fn.extend({ uploadPreview: function (opts) { var _self = this, _this = $(thi ...
随机推荐
- 更少的直接百度,更多的取看API
很多时候我们会对于一个jar包中的一个类的某个方法犯迷糊 我们不知道传进去什么样子的参数,这个方法的返回值到底是什么样的. 更多的时候我们不知道这个jar中有没有我们想要的这个方法. 很多时候以前我都 ...
- Android网络开发之Volley--Volley自定义Request
1.自定义一个解析Json的Request,这里使用JackSon框架来解析Json.你也可以自定义一个解析XML的Request,或者使用FastSon来解析Json. 2.我们首先来看一下Stri ...
- EXCEL读写NPOI--导出功能
第一步:将NPOI中的一下三个文件复制到项目中
- Java IO整理
参考博客:http://www.cnblogs.com/rollenholt/archive/2011/09/11/2173787.html Java IO体系结构 1.要弄清楚其体系结构,先明白 ...
- CCS设计手段——相对定位
1.认识相对定位 相对定位就是让元素相对自己原来的位置进行位置调整. 2.相对定位的本质特性 不脱标,老家留坑,形影分离. 3.用途 ①微调位置 ②做绝对定位的参考,子绝父相 4.相对定位的定位置 相 ...
- office web apps部署(二)
1.安装composer 参考 http://docs.phpcomposer.com/00-intro.md 根据系统选择安装方式 修改php.ini 去掉extension=php_opens ...
- PHP和MySQL Web开发(原书第4版) 高清PDF+源代码
PHP和MySQL Web开发(原书第4版) 高清PDF+源代码 [日期:2014-08-06] 来源:Linux社区 作者:Linux [字体:大 中 小] 内容简介 <PHP和My ...
- 基于LNMP的Zabbbix之Zabbix Agent源码详细安装,但不给图
基于LNMP的Zabbbix之Zabbix Server源码详细安装:http://www.cnblogs.com/losbyday/p/5828547.html wget http://jaist. ...
- [iOS Animation]-CALayer 专用图层
专用图层 复杂的组织都是专门化的 Catharine R. Stimpson 到目前为止,我们已经探讨过CALayer类了,同时我们也了解到了一些非常有用的绘图和动画功能.但是Core Animati ...
- 【bzoj1552】[Cerc2007]robotic sort
题目描述 输入 输入共两行,第一行为一个整数N,N表示物品的个数,1<=N<=100000.第二行为N个用空格隔开的正整数,表示N个物品最初排列的编号. 输出 输出共一行,N个用空格隔开的 ...