Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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 在Hover jquery上更改Href的一部分_Javascript_Jquery - Fatal编程技术网

Javascript 在Hover jquery上更改Href的一部分

Javascript 在Hover jquery上更改Href的一部分,javascript,jquery,Javascript,Jquery,我有一个链接(mysite.com/#第1页,#第2页…)。我不想在悬停(#->/)时分别将其更改为/page-1和/page-2。 可能吗 我试着走这条路: $('.page-link').hover(function() { var text = $(this).href(); $(this).href(href.replace('#', '')); }); 首先,采用2功能;一个用于输入,一个用于输出 $('.page-link').hover( // mo

我有一个链接(mysite.com/#第1页,#第2页…)。我不想在悬停(#->/)时分别将其更改为/page-1和/page-2。 可能吗

我试着走这条路:

$('.page-link').hover(function() {
    var text = $(this).href();
    $(this).href(href.replace('#', '')); 
});   
首先,采用2功能;一个用于
输入
,一个用于
输出

$('.page-link').hover(

  // mousein
  function() {

    // cache the original href
    $(this).data("href", $(this).attr("href"));

    // replace the existing href
    $(this).attr("href", function(idx, val) {

      // regexp match the page number
      // $1 will be set to literal string "#page-"
      // $2 will be a string of the page number
      return val.replace(/(#page-)(\d+)$/, function(str, $1, $2) {

        // parse as int and increment by 1
        return $1 + (parseInt($2, 10) + 1);
      });
    });
  },

  // mouseout
  function() {

    // restore the original href from the "cache"
    $(this).attr("href", $(this).data("href"));

    // clear the cache
    $(this).data("href", null);
  }
);
演示时间到了,对吗

$('.page link')。悬停(
函数(){
$(this.data(“href”),$(this.attr(“href”);
$(this.attr(“href”),函数(idx,val){
return val.replace(/(#page-)(\d+)$/,函数(str,$1,$2){
返回$1+(parseInt($2,10)+1);
});
});
},
函数(){
$(this.attr(“href”),$(this.data(“href”);
$(this).data(“href”,null);
}
);


href.replace
应该是
文本。replace
。完美答案。这真的很有帮助。谢谢