【动态创建script来加载-推荐】

function loadJS( url, callback ){

var script = document.createElement('script'),

    fn = callback || function(){};

script.type = 'text/javascript';



//IE

if(script.readyState){

    script.onreadystatechange = function(){

        if( script.readyState == 'loaded' || script.readyState == 'complete' ){

            script.onreadystatechange = null;

            fn();

        }

    };

}else{

    //其他浏览器

    script.onload = function(){

        fn();

    };

}

script.src = url;

document.getElementsByTagName('head')[0].appendChild(script);

}

//用法

loadJS('file.js',function(){

alert(1);

});

引用:https://www.cnblogs.com/telwanggs/p/11045773.html

原文:https://www.cnblogs.com/010101-/p/10649026.html

通过css控制,可以实现加载网络图片时,未加载完成的时候显示本地一张占位图,加载完成后显示网络图片;

原理:通过在img标签的after伪元素上添加一张占位图,并且img都设置为position:relative;after设置position:absolute;img标签的src为网络图片,这样加载的时候由于网络图片没加载完成,就会显示本地图片,下面案例中的js是为了效果明显而故意延时设置img的src属性。

代码改版(将原作者的占位图改为padding-bottom)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        img {
            position: relative;
            width: 100%;
            height: 100%;
        }
        
        img::after {
            content: "";
            height: 100%;
            width: 100%;
            position: absolute;
            left: 0;
            top: 0;
            background-color: #eee;
            padding-bottom: 100%;
        }
        div{
            width: 600px;
            height: auto;
        }
        
    </style>
</head>

<body>
    <div>
        <img src="">
    </div>
    
</body>
<script>
    setTimeout(function() {
        document.querySelectorAll("img")[0].src = 'https://img.kzcn.cc/600x600/c/0';
    }, 3000);
</script>

</html>

document.onkeydown=function(e){
    if ($('.text-area').is(":focus")) {
        if(e.keyCode == 13 && e.ctrlKey){
            var changeText = $('text-area').val() + "\n";
            $('text-area').val(changeText);
        }else if(e.keyCode == 13){
            // 避免回车键换行
            e.preventDefault();
            $('.dsChat_send').click();
        }
    }
}

replace(正则不要用引号,'需要替换内容')