JS检测图片无法加载自动加载默认图

<script>

            //function imgerror(img){

            // img.src="/pic/nopic.gif";

             //img.οnerrοr=null;   //控制不要一直跳动 

             

             

              $(document).ready(function(){

                $('img').each(function(){

                    var tt=$(this).attr('src');

                    //console.log(tt);

                    if(tt==""){

                        $(this).attr('src','/pic/nopic.gif');

                    }else{

                        $(this).error(function(){

                            $(this).attr('src','/pic/nopic.gif');

                        })

                    }

                });

            })

    </script>


Copyright Liukaiweb.Com Rights Reserved.

 渝ICP备2021008408号-5