JS是否可以在网页打开时获取当前页面的网址?
如果可以,那么:
网页:1.html,2.html,3.html,4.html,5.html,6.html,
图片:1.jpg,2.jpg,3.jpg,4.jpg,5.jpg,6.jpg,目标:显示某个网页时,根据网页的文件名在页面内显示对应的图片。
比如:打开1.html时显示图片1.jpg,打开2.html时显示2.jpg.

解决方案 »

  1.   

    当然可以,
    js获取网页地址及参数var url=location.search; //获取参数集
    var url2 = window.location.href ; 获取全路径if( url.indexOf("?")!=-1){var str = url.substr(1);
    strs = str.split("&");
    for(var i=0;i<strs.length;i++) {
    document.write(strs[i].split("=")[0] +" = "+ strs[i].split("=")[1] + "\n");
    }}
      

  2.   

    location属性应该是网址了吧,试试看
      

  3.   

    那再引申一下,网页的名字是已经的,abc.html dce.html fagh.html ifhl.html mcn.html
    然后图片是 hello.jpg hi.jpg wolf.jpg apple.jpg orange.jpg这样子要如何写呢?
      

  4.   

    那再引申一下,网页的名字是已经的,abc.html dce.html fagh.html ifhl.html mcn.html
    然后图片是 hello.jpg hi.jpg wolf.jpg apple.jpg orange.jpg您就不能吧图片设置成和网页一样的名称
      

  5.   


    <pageface>
        <page>
            <name>aaa.html</name>
            <face>d78d.jpg</face>
        </page>
        <page>
            <name>dfh.html</name>
            <face>q3fg.jpg</face>
        </page>
    </pageface>
    实在不能改图片名,那就写一个XML的配置文件,用Ajax读取之后解析获取与页面相关联的图片名称。
      

  6.   


    这难道很难?
    <img id="show">
    <script>
    var keys = window.location.href.replace(/^.*\/(.+)\..*$/g, "$1");
    var imgo = {"abc":"hello", "dce":"hi", "fagh":"wolf", "ifhl":"apple", "mcn":"orange"};
    document.getElementById("show").src = imgo[keys] + ".jpg"
    </script>
      

  7.   

    :1、循序渐进的学习Windows Embedded系统入门课程,包括什么?
    答案:E 
     
      

  8.   

    :1、循序渐进的学习Windows Embedded系统入门课程,包括什么?
    答案:E 
     
      

  9.   

    <html>
    <head>
        <title>无标题页</title>
        <script type="text/javascript" src="JScript.js"></script>
    </head>
    <body onload="showImg('imgShow','这里传入图片路径')">
        <div>
            <img id="imgShow" src="" alt="Image" />
        </div>
    </body>
    </html>JScript.js内容如下:
    function showImg(id, imgPath)
    {
        var nStart = window.location.href.lastIndexOf('/');
        var nEnd = window.location.href.indexOf('.');
        var url_name = window.location.href.substring(nStart+1,nEnd);
        var imgs_names = {"abc":"hello", "dce":"hi", "fagh":"wolf", "ifhl":"apple", "mcn":"orange"};
        
        document.getElementById(id).src = imgPath + imgs_names[url_name] + ".jpg"
    }
      

  10.   

    在CMS中找到了一个输出栏目ID的标签,改了图片文件名,不用脚本就可以实现了,谢谢大家。