<html>
    <head>
        <title>示例页面</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
       <style type="text/css">
                html, body {
                     background:#3d71b8 url(image/spin.jpg) no-repeat top center;
                        font: normal 12px tahoma, arial, verdana, sans-serif;
                     margin: 0;
                     padding: 0;
                     border: 0 none;
                     overflow: hidden;
                     height: 100%;
                }
        </style>
        <script type="text/javascript">
            window.onload = function(){
                    var img_name = document.location.href.split("=")[1];//值为shop
                    var img_obj = document.body.currentStyle.backgroundImage;//值为:"url("http://10.16.133.138:8080/zjkdsc/business/process/image/ship.jpg")";
                    alert(img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($0,$1){return $0.replace($1,img_name);})); //值为:"url("http://10.16.133.138:8080/zjkdsc/business/process/image/shop.jpg")";
                    document.body.currentStyle.backgroundImage = img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($0,$1){return $0.replace($1,img_name);});
                    //报脚本错,无效的过程调用或参数.
                };   
        </script>
    </head>    <body >
      
    </body></html>

解决方案 »

  1.   

    try:
    document.body.currentStyle.backgroundImage 
    ====>
    document.body.style.backgroundImage 
      

  2.   

    试过了,又报缺少';'.晕,用jsLink检测过了,并没有语法错误,能再帮忙分析一下不
      

  3.   

    我这边没报错呀
    <html>
        <head>
            <title>示例页面</title>
            <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
           <style type="text/css">
                    html, body {
                            background:#3d71b8 url(image/spin.jpg) no-repeat top center;
                            font: normal 12px tahoma, arial, verdana, sans-serif;
                            margin: 0;
                            padding: 0;
                            border: 0 none;
                            overflow: hidden;
                            height: 100%;
                    }
            </style>
            <script type="text/javascript">
                window.onload = function(){
                        var img_name = document.location.href.split("=")[1];//值为shop
                        var img_obj = document.body.currentStyle.backgroundImage;//值为:"url("http://10.16.133.138:8080/zjkdsc/business/process/image/ship.jpg")";
                        alert(img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($0,$1){return $0.replace($1,img_name);})); //值为:"url("http://10.16.133.138:8080/zjkdsc/business/process/image/shop.jpg")";
                        document.body.style.backgroundImage = img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($1,$1){return $1.replace($1,img_name);});
                        //报脚本错,无效的过程调用或参数.
                    };   
            </script>
        </head>    <body >
          
        </body></html>
      

  4.   

    document.body.currentStyle.backgroundImage = img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($0,$1){return $0.replace($1,img_name);});改为:
    document.body.style.backgroundImage = "url('img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($0,$1){return $0.replace($1,img_name);})')";
      

  5.   

    function getCurrentStyle(element){
    return element.currentStyle || document.defaultView.getComputedStyle(element, null);
    };
    window.onload = function(){
    var img_name = document.location.href.split("=")[1];
    var img_obj = getCurrentStyle(document.body).backgroundImage;
    alert(img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi, function($0, $1){
    return $0.replace($1, img_name);
    }));
    document.body.style.backgroundImage = img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi, function($0, $1){
    return $0.replace($1, img_name);
    });
    };
      

  6.   

    搞错了:
    document.body.style.backgroundImage = "url('" + img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($0,$1){return $0.replace($1,img_name);}) + "')"; 
      

  7.   

    感谢lihui_shine和xfsnero,问题似乎解决了.可是产生了新问题. alert(img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi, function($0, $1){
            return $0.replace($1, img_name);
        }));回调函数引用外部变量img_name,格外加上了一个双引号.导致图片出不来,为什么.注意这里.
    "url("http://10.16.133.138:8080/zjkdsc/business/process/image/"shop".jpg")"shop上的双引号,为什么会这样.直接 return $0.replace($1, "shop");就不会有这样的问题
      

  8.   

    oldmht,你那个不行呢.我试过了.
      

  9.   

    try:document.body.style.backgroundImage = img_obj.replace(/(?:image\/)(.*)(?:\.jpg)/gi,function($0,$1,img_name){return $0.replace($1,img_name);});
      

  10.   

    谢谢大家,问题解决了.csdn的热心人是很多的.
    惭愧,框架用多了,自己写原生代码都退步了.
    忽略了一些细节..
      

  11.   


    //你写的代码怎么这么长?
    //不可以这样么
    var img_name = document.location.href.split("=")[1];//值为shop
    var img_obj = document.body.currentStyle.backgroundImage;//值为:"url("http://10.16.133.138:8080/zjkdsc/business/process/image/ship.jpg")";
    var img_name_old = img_obj.split("process/image/")[1].split(".jpg").[0];//值为:ship
    document.body.currentStyle.backgroundImage = img_obj.split(img_name_old).join(img_name);