您好,欢迎访问一九零五行业门户网

discuz中用到的javascript函数解析[原创]第1/2页_javascript技巧

var lang = new array();
var useragent = navigator.useragent.tolowercase();
var is_opera = useragent.indexof('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'gecko') && useragent.substr(useragent.indexof('firefox') + 8, 3);
var is_ie = (useragent.indexof('msie') != -1 && !is_opera) && useragent.substr(useragent.indexof('msie') + 5, 3);
function $(id) {
    return document.getelementbyid(id);
}
//定义数组的push属性
array.prototype.push = function(value) {
    this[this.length] = value;
    return this.length;
}
//javascript全选函数
function checkall(form, prefix, checkall) {
    var checkall = checkall ? checkall : 'chkall';
    for(var i = 0; i < form.elements.length; i++) {
var e = form.elements[i];
if(e.name && e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
e.checked = form.elements[checkall].checked;
}
}
}
function doane(event) {
e = event ? event : window.event;
if(is_ie) {
e.returnvalue = false;
e.cancelbubble = true;
} else if(e) {
e.stoppropagation();
e.preventdefault();
}
}
function fetchcheckbox(cbn) {
return $(cbn) && $(cbn).checked == true ? 1 : 0;
}
function getcookie(name) {
var cookie_start = document.cookie.indexof(name);
var cookie_end = document.cookie.indexof(";", cookie_start);
return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
function thumbimg(obj) {
    var zw = obj.width;
    var zh = obj.height;
    if(is_ie && zw == 0 && zh == 0) {
        var matches;
        re = /width=([']?)(\d+)(\1)/i;
        matches = re.exec(obj.outerhtml);
        zw = matches[2];
        re = /height=([']?)(\d+)(\1)/i;
        matches = re.exec(obj.outerhtml);
        zh = matches[2];
    }
    obj.resized = true;
    obj.style.width = zw + 'px';
    obj.style.height = 'auto';
    if(obj.offsetheight > zh) {
        obj.style.height = zh + 'px';
        obj.style.width = 'auto';
    }
    if(is_ie) {
        var imgid = 'img_' + math.random();
        obj.id = imgid;
        settimeout('try {if ($(\''+imgid+'\').offsetheight > '+zh+') {$(\''+imgid+'\').style.height = \''+zh+'px\';$(\''+imgid+'\').style.width = \'auto\';}} catch(e){}', 1000);
    }
    obj.onload = null;
}
function imgzoom(obj) {}
function in_array(needle, haystack) {
    if(typeof needle == 'string' || typeof needle == 'number') {
        for(var i in haystack) {
            if(haystack[i] == needle) {
                    return true;
            }
        }
    }
    return false;
}
function setcopy(text, alertmsg){
    if(is_ie) {
        clipboarddata.setdata('text', text);
        alert(alertmsg);
    } else if(prompt('press ctrl+c copy to clipboard', text)) {
        alert(alertmsg);
    }
}
function isundefined(variable) {
    return typeof variable == 'undefined' ? true : false;
}
function mb_strlen(str) {
    var len = 0;
    for(var i = 0; i < str.length; i++) {
        len += str.charcodeat(i)
其它类似信息

推荐信息