jQuery更改页面中的所有链接 [英] jQuery to change all the links in the page

查看:126
本文介绍了jQuery更改页面中的所有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 $(function(){
            $('a').each(function(){
                        var x=this.href;
                        this.href="www.somesitename.com/filter"+this.href;
                  });
         });

我写了上面的jQuery脚本,将一些站点名称附加到页面中的所有链接上,但无法正常工作.

i wrote the above jQuery script to append some site name to all the links in the page but it's not working as expected.

推荐答案

我不知道您为什么要使用jQuery来实现这种基本行为...

I wonder why would you use jQuery for such basic behaviour...

这就是为什么标记BASE 的原因在那里

that is why the tag BASE is there for

为页面上的所有链接指定默认URL 默认目标:

<head>
    <base href="http://www.w3schools.com/images/" />
    <base target="_blank" />
</head>

<body>
    <img src="stickman.gif" />
    <a href="http://www.w3schools.com">W3Schools</a>
</body>

不要使简单的事情复杂化!

don't complicate what is simple!

已添加

来自站点点

仅当您所有相对链接表单提交都位于同一位置时,基本元素才对您有用.

The base element is only going to be useful to you if all your relative links or form submissions go to the same location.

这篇关于jQuery更改页面中的所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆