如何使用 JQuery 将一个 URL 更改为另一个 URL
我有以下脚本:
<script>
safari.application.addEventListener("command", performCommand, false);
function performCommand(event) {
if (event.command == "change") {
$('a[href="http://example.com"]').attr('href', 'http://sub.example.com');
}
}
</script>
我想要发生的是,当按下菜单栏按钮时,它会运行中间的代码(在本例中为 ('a[href="http://example.com "]').attr('href', 'http://sub.example.com');
) 查找所有链接并将其替换为修改后的版本。我怎样才能做到这一点?
I have the following script:
<script>
safari.application.addEventListener("command", performCommand, false);
function performCommand(event) {
if (event.command == "change") {
$('a[href="http://example.com"]').attr('href', 'http://sub.example.com');
}
}
</script>
And what I want to happen is that when the menu bar button is pressed, it runs the code in between (in this case, ('a[href="http://example.com"]').attr('href', 'http://sub.example.com');
) which finds all links and replaces them with the modified version. How can I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要更改选择器,以便它只查找以您想要的域开头的链接。这可以使用 ^=
而不仅仅是
=` 来完成:you may want to change your selector so it only finds links that begin with the domain you'd like. This can be accomplished using ^=
instead of just
=`: