标签 JS 下的文章

JS - 同一界面内实例化2个编辑器

js

//实例化编辑器editor
var ue = UE.getEditor('editor');
//实例化编辑器editor2
var ue2 = UE.getEditor('editor2');
function removeformat() {
    //全选
    ue.execCommand('selectall');
    //未格式化的内容
    var content1 = ue.getContent();
    //清除格式
    ue.execCommand('removeformat');
    //格式化后的内容
    var content2 = ue.getContent();
    //过滤掉 
    content2 = content2.replace(/ /g, "");
    //过滤掉<p><br/></p>
    content2 = content2.replace(/<p><br\/><\/p>/g, "");
    //保留原来的内容
    ue.setContent(content1, false);
    //将内容赋予编辑器2
    ue2.setContent(content2, false);
}

阅读全文

JS - F12 网页跳转

js

function collect() {
    //开始javascript执行过程的数据收集
    console.profile();
    //配合profile方法,作为数据收集的结束
    console.profileEnd();
    //我们判断一下profiles里面有没有东西,如果有,肯定有人按F12了,没错!!  
    if (console.clear) {
        //清空控制台
        console.clear()
    };
    if (typeof console.profiles == "object") {
        return console.profiles.length > 0;
    }
}
function check() {
    if ((window.console && (console.firebug || console.table && /firebug/i.test(console.table()))) || (typeof opera == 'object' && typeof opera.postError == 'function' && console.profile.length > 0)) {
        jump();
    }
    if (typeof console.profiles == "object" && console.profiles.length > 0) {
        jump();
    }
}
check();
window.onresize = function() {
    //判断当前窗口内页高度和窗口高度
    if ((window.outerHeight - window.innerHeight) > 200)
    jump();
}
function jump() {
    window.location = "http://xiaowiba.com";
}

阅读全文

JS - 鼠标点击彩色爱心特效

js

(function(window, document, undefined) {
    var hearts = [];
    window.requestAnimationFrame = (function() {
        return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
        function(callback) {
            setTimeout(callback, 1000 / 60);
        }
    })();
    init();
    function init() {
        css(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
        attachEvent();
        gameloop();
    }
    function gameloop() {
        for (var i = 0; i < hearts.length; i++) {
            if (hearts[i].alpha <= 0) {
                document.body.removeChild(hearts[i].el);
                hearts.splice(i, 1);
                continue;
            }
            hearts[i].y--;
            hearts[i].scale += 0.004;
            hearts[i].alpha -= 0.013;
            hearts[i].el.style.cssText = "left:" + hearts[i].x + "px;top:" + hearts[i].y + "px;opacity:" + hearts[i].alpha + ";transform:scale(" + hearts[i].scale + "," + hearts[i].scale + ") rotate(45deg);background:" + hearts[i].color;
        }
        requestAnimationFrame(gameloop);
    }
    function attachEvent() {
        var old = typeof window.onclick === "function" && window.onclick;
        window.onclick = function(event) {
            old && old();
            createHeart(event);
        }
    }
    function createHeart(event) {
        var d = document.createElement("div");
        d.className = "heart";
        hearts.push({
            el: d,
            x: event.clientX - 5,
            y: event.clientY - 5,
            scale: 1,
            alpha: 1,
            color: randomColor()
        });
        document.body.appendChild(d);
    }
    function css(css) {
        var style = document.createElement("style");
        style.type = "text/css";
        try {
            style.appendChild(document.createTextNode(css));
        } catch (ex) {
            style.styleSheet.cssText = css;
        }
        document.getElementsByTagName('head')[0].appendChild(style);
    }
    function randomColor() {
        return "rgb(" + (~~ (Math.random() * 255)) + "," + (~~ (Math.random() * 255)) + "," + (~~ (Math.random() * 255)) + ")";
    }
})(window, document);

JS - 全部选择、取消全部选择 - 1

js

window.onload = function() {
                //全部选择
                document.getElementById('checkall').onclick = function() {
                    //获取文档中所有的input元素
                    var obj = document.getElementsByTagName('input');
                    for (var i = 0; i < obj.length; i ++) {
                        if (obj[i].type == 'checkbox') {
                            obj[i].checked = true;
                            //设置复选框元素对象的checked属性值为true就能勾选该复选框
                            //false即为取消选择
                        }
                    }
                }
                //全部取消选择
                document.getElementById('deselect').onclick = function() {
                    var obj = document.getElementsByTagName('input');
                    for (var i = 0; i < obj.length; i ++) {
                        if (obj[i].type == 'checkbox') {
                            obj[i].checked = false;
                        }
                    }
                }
            }

阅读全文

JS - 删除数据前的确认

<a 
    href="?action=del&id={$val['id']}&name={$val['name']}" 
    onclick="if(confirm('确实要删除数据吗?')) return true;else return false;">
    <b>删除</b>
</a>

JS - 简繁转换

代码

<a id="translateLink" href="">繁體</a>
<script type="text/javascript" src="./js/jianfan.js"></script> 
<script type="text/javascript"> 
var defaultEncoding = 0; //默认是否繁体,0-简体,1-繁体 
var translateDelay = 0; //延迟时间,若不在</body>前, 要设定延迟翻译时间, 如100表示100ms,默认为0 
var cookieDomain = "http://你的网站地址"; //Cookie地址, 一定要设定, 通常为你的网址 
var msgToTraditionalChinese = "繁體"; //默认切换为繁体时显示的中文字符 
var msgToSimplifiedChinese = "简体"; //默认切换为简体时显示的中文字符 
var translateButtonId = "translateLink"; //默认互换id 
translateInitilization(); 
</script>

阅读全文