Web前端开发交互过程中需各种转换的函数封装

微信前端界面开发
微信小程序与前端开发的区别
微信小程序群功能开发-前端篇

html 代码

<script>
    //处理各种异常文本
    function dispose(flag, str) {
        var result = ”
        switch (flag) {
            case 1:
                result = str ? str : ”
                break
            case 2:
                result = str ? str : 0
                break
            case 3:
                result = str ? str : ‘匿名’
                break
            case 4:
                result = str ? str : ‘未知地区’
                break
            case 5:
                result = str ? str : ‘未知’
                break
        }
        return result
    }
    //作品状态
    function getWorkStus(type) {
        var value = ”
        if (type == 0) {
            value = ‘未售’
        } else if (type == 1) {
            value = ‘已售’
        } else if (type == 2) {
            value = ‘收藏’
        }
        return value
    }
    //作品类别
    function getWorkType(typeArr, id) {
        var value = ”
        for (i in typeArr) {
            if (id == typeArr[i].id) {
                value = typeArr[i].name
            }
        }
        return value
    }
    //截取字符串
    function omit1(str, num) {
        if (str) {
            if (str.length > num) {
                str = str.substring(0, num) + ‘…’
            }
        } else {
            str = ”
        }
        return str
    }
</script>

html 代码

<script>
    // 进入全屏
    function fullScreen() {
        var el = document.documentElement
        var rfs =
            el.requestFullScreen ||
            el.webkitRequestFullScreen ||
            el.mozRequestFullScreen ||
            el.msRequestFullScreen
        if (typeof rfs != ‘undefined’ && rfs) {
            rfs.call(el)
        } else if (typeof window.ActiveXObject != ‘undefined’) {
            // for Internet Explorer
            var wscript = new ActiveXObject(‘WScript.Shell’)
            if (wscript != null) {
                wscript.SendKeys(‘{F11}’)
            }
        }
    }
    // 退出全屏
    function exitFullScreen() {
        var el = document,
            cfs =
                el.cancelFullScreen ||
                el.webkitCancelFullScreen ||
                el.mozCancelFullScreen ||
                el.exitFullScreen,
            wscript
        if (typeof cfs != ‘undefined’ && cfs) {
            cfs.call(el)
            return
        }
        if (typeof window.ActiveXObject != ‘undefined’) {
            wscript = new ActiveXObject(‘WScript.Shell’)
            if (wscript != null) {
                wscript.SendKeys(‘{F11}’)
            }
        }
    }
</script>
web前端微信开发
微信h5开发前端
前端开发 扫一扫微信支付
» 本文来自:前端开发者 » 《Web前端开发交互过程中需各种转换的函数封装》
» 本文链接地址:https://www.rokub.com/7210.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!