Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript获取href地址和更改_Javascript_Jquery_Html_Greasemonkey - Fatal编程技术网

javascript获取href地址和更改

javascript获取href地址和更改,javascript,jquery,html,greasemonkey,Javascript,Jquery,Html,Greasemonkey,我需要获取href值并更改它,然后在新选项卡中自动打开 页面中的地址标记 <a href="http://xxxxx/first_123.html" id="view-1" class="view button_green" style="margin: 10px;">view</a> 然后打开http://xxx/first_123.html自动进入新选项卡 我用Greasemonkey。谢谢。HTML <a href="http://xxxxx/first_1

我需要获取href值并更改它,然后在新选项卡中自动打开

页面中的地址标记

<a href="http://xxxxx/first_123.html" id="view-1" class="view button_green" style="margin: 10px;">view</a>
然后打开
http://xxx/first_123.html
自动进入新选项卡

我用Greasemonkey。谢谢。

HTML

<a href="http://xxxxx/first_123.html" id="view-1" class="view button_green" style="margin: 10px;">view</a>

您似乎忘记了问问题,或者确实向我们展示了您在使用Anks freefaller时遇到问题的代码。我有“id=“view-1”class=“view button\u green”style=“margin:10px;“>查看我想获取href值并更改为,然后在tew选项卡中打开第二个。冒着被系统自动删除的风险,我建议您在询问StackOverflow问题之前先阅读以下网站:
<a href="http://xxxxx/first_123.html" id="view-1" class="view button_green" style="margin: 10px;">view</a>
$(document).ready(function(){
      $("#view-1").click(function(e){
        e.preventDefault();
        var _curr_href= $(this).attr("href");
        $(this).attr("href", _curr_href.replace("first", "second"));
        window.open(_curr_href);
      });
});