Javascript 在Hover jquery上更改Href的一部分
我有一个链接(mysite.com/#第1页,#第2页…)。我不想在悬停(#->/)时分别将其更改为/page-1和/page-2。 可能吗 我试着走这条路: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
$('.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
。完美答案。这真的很有帮助。谢谢