首页 > web前端 > js教程 > 正文

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

PHP中文网
发布: 2016-05-16 19:04:20
原创
1216人浏览过

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         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         len += str.charcodeat(i) 

java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号