分类 代码 下的文章

ajax - 删除前的确认

if(confirm('确认删除图片' + selectItem.join(",") + '吗?')) {
        $.ajax({
            url: "del/batchdel",
            type: 'POST',
            dataType: 'json',
            data: 'items=' + selectItem.join(","),
            success: function (data) {
                if (data.code == 200) {
                    errorDis(data.info);
                    refresh();
                } else {
                    errorDis(data.info);
                    return false;
                }
            }
        });
    }

JS - 点击直接下载

js

function download(src) {
    var a = document.createElement('a');
    a.setAttribute("href", src);
    a.setAttribute("download", "");
    var evObj = document.createEvent('MouseEvents');
    evObj.initMouseEvent( 'click', true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
    a.dispatchEvent(evObj);
};

阅读全文

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;
                        }
                    }
                }
            }

阅读全文

ajax - 提交 checkbox

html

<button class="batchdel" id="submitbatchdel" type="submit">
    <a href="" onclick="if(confirm('确定要删除数据吗?')) return true;else return false;">批量删除</a>
</button>

阅读全文

PHP - 清空目录下文件

//清空文件操作
function delDirAndFile($dirName){
    if($handle = opendir("$dirName")){
        while(false !== ($item = readdir($handle))){
            if($item != "." && $item != ".."){
                if(is_dir("$dirName/$item")){
                    delDirAndFile("$dirName/$item");
                }else{
                    if(unlink("$dirName/$item")){
                        //echo "成功删除文件: $dirName/$item\n";
                    }
                }
            }
        }
        closedir($handle);
        if(rmdir($dirName)){
            //echo "成功删除目录: $dirName\n";
        }
    }
}

PHP - 遍历目录下的文件

//遍历目录下的文件
function rmdi_r($dirname){
    //判断是否为一个目录,非目录直接关闭
    if(is_dir($dirname)){
        //如果是目录,打开他
        $name = opendir($dirname);
        //使用while循环遍历
        $i = 0;
        while($file = readdir($name)){
            //去掉本目录和上级目录的点
            if($file == "." || $file == ".."){
                continue;
            }
            //如果目录里面还有一个目录,再次回调
            if(is_dir($dirname."/".$file)){
                rmdi_r($dirname."/".$file);
            }
            //exit();
            //如果目录里面是个文件,那么输出文件名
            if(is_file($dirname."/".$file)){
                echo "<li class=''>序号:".($i+1)."|路径:".$dirname."/".$file."</li>";
            }
            $i++;
        }
        //遍历完毕关闭文件
        closedir($name);
        //输出目录名
        //echo("目录名称:".$dirname);
        echo "<b>当下目录内还有".$i."个文件</b>";
        if($i == 0){//目录为空提示语
            echo "该目录为空";
        }else{}
    }
}