赞
踩
function JsonFuction(zu,ins,dx){if(ins!=null)zu.splice(dx,1,ins); else delete zu[dx];}
//JsonFuction(参数JsonList,null,Idex),表示从JSON数组里面删除一个项目,Idex表示当前索引
//JsonFuction(参数JsonList,NewProJect,Idex),表示从JSON数组里面替换一个项目为NewProJect
function setCursorPosition(ctrl, pos){
if(ctrl.setSelectionRange){ctrl.focus();
ctrl.setSelectionRange(pos,pos);}
else if (ctrl.createTextRange) {
var range = ctrl.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();}}//设置ctrl对象DOM输入框当前的游标下标为pos
function shuziCheck(id){var i=id.selectionStart;var b=/\D/.test(id.value);id.value=id.value.replace(/\D/g,'');
if(b)setCursorPosition(id,i-1);else setCursorPosition(id,i)}//侦测输入是不是数字
function checkContentNull(form){
var str="",inp=form.getElementsByTagName('input'),i;
for(i=0;i<inp.length;i++){
if(inp[i].type!="hidden")
if(inp[i].alt!=undefined&&inp[i].alt!="")
if(trim(inp[i].value)==""||inp[i].value==$(form).find("input[alt='"+inp[i].alt+"']").eq(0).attr("placeholder")){
str+=inp[i].alt+" 不能为空\n"
}
};inp=form.getElementsByTagName('textarea');
for(i=0;i<inp.length;i++){
if(inp[i].title!=undefined&&inp[i].title!="")
if(inp[i].value==""){
str+=inp[i].title+" 不能为空!\n"
}
};inp=form.getElementsByTagName('select');
for(i=0;i<inp.length;i++){
if(inp[i].title!=undefined&&inp[i].title!="")
if(inp[i].selectedIndex==0){
str+=inp[i].title+" 不能为空!\n"
}
}
if(str!=""){
alert(str);
return false;
}else return true;
}//检测输入框里面的内容是不是空,给input添加一个alt,并给alt一个前面的名字为标识,给textarea与select则用title作为标识
function getElementViewTop(element){
var actualTop = element.offsetTop;
var current = element.offsetParent;
while (current !== null){actualTop += current. offsetTop;
current = current.offsetParent;}
if (document.compatMode == "BackCompat"){
var elementScrollTop=document.body.scrollTop;
} else {var elementScrollTop=document.documentElement.scrollTop; }
return actualTop-elementScrollTop;}//寻找position为absolute的元素离父元素如果没有则是body,离top的距离
function getElementViewLeft(element){
var actualLeft = element.offsetLeft;
var current = element.offsetParent;
while (current !== null){
actualLeft += current.offsetLeft;
current = current.offsetParent;}
if (document.compatMode == "BackCompat"){
var elementScrollLeft=document.body.scrollLeft;} else {
var elementScrollLeft=document.documentElement.scrollLeft;
}return actualLeft-elementScrollLeft;}//寻找相对元素离父元素的左边的距离
function getCookie(cookie){
var arrCookie = document.cookie.split("; ");
for (var i = 0; i < arrCookie.length; i++) {
var arr = arrCookie[i].split("=");
if (arr[0] == cookie) {
return arr[1];
}
}
}//<script>document.write(getCookie("checkcode"));</script>这样用js来提取Cookie到页面的元素当Text使用
function randomNum(min,max){
return Math.round(Math.random()*(max-min)+min)
}//生成一个随机数字,有最大最小范围区间
function banBubbler(e){
if (e || e.stopPropagation){e.stopPropagation();}
else {window.event.CancelBubble = true;}
}//取消事件冒泡泡
function chuFa(Element,str,events){
if(document.all) {Element.click();}
else{var e=document.createEvent(events)
e.initEvent(str, true, true);
Element.dispatchEvent(e);}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。