common.js
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***禁止滑动***/
function stop() {
document.body.style.overflow = 'hidden';
// document.addEventListener("touchmove", mo, false); //禁止页面滑动
$("body").on("touchmove",function(event){
event.preventDefault();
}, false)
}
/***取消滑动限制***/
function move() {
document.body.style.overflow = ''; //出现滚动条
// document.removeEventListener("touchmove", mo, false);
$("body").off("touchmove");
}
function toast(that) {
var $toast = $('#toast');
stop()
$toast.find(".weui-toast__content").html(that)
if ($toast.css('display') != 'none') return;
$toast.fadeIn(100);
setTimeout(function () {
$toast.fadeOut(100);
move()
}, 2000);
}
//到即时
var countdown=60;
function settime(val) {
if (countdown == 0) {
val.removeAttribute("disabled");
val.value="获取验证码";
countdown = 60;
} else {
val.setAttribute("disabled", true);
val.value= countdown +"s";
countdown--;
setTimeout(function() {
settime(val)
},1000)
}
}
//选择头像上传
function setImagePreview(avalue,obj) {
var docObj = document.getElementById("doc");
//img
var imgObjPreview = document.getElementById("preview");
//div
var divs = document.getElementById(obj);
if (docObj.files && docObj.files[0]) {
//火狐下,直接设img属性
imgObjPreview.style.display = 'block';
imgObjPreview.style.width = '100'+"%";
imgObjPreview.style.height = '100%';
//imgObjPreview.src = docObj.files[0].getAsDataURL();
//火狐7以上版本不能用上面的getAsDataURL()方式获取,需要一下方式
imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
} else {
//IE下,使用滤镜
docObj.select();
var imgSrc = document.selection.createRange().text;
var localImagId = document.getElementById("localImag");
//必须设置初始大小
localImagId.style.width = "100px";
localImagId.style.height = "100px";
//图片异常的捕捉,防止用户修改后缀来伪造图片
try {
localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)"
localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
} catch(e) {
alert("您上传的图片格式不正确,请重新选择!");
return false;
}
imgObjPreview.style.display = 'none';
document.selection.empty();
}
return true;
}