如何使用jQuery更改href属性onmouseover? [英] How can I change href attribute onmouseover using jQuery?
本文介绍了如何使用jQuery更改href属性onmouseover?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请原谅我的无知,但我一直在寻找这一段时间,我不知道如何改变以下的href:
Excuse my ignorance but I've been searching for this for a while and I can't figure out how to change the href of the following:
<a id="p2749244"class="nohover"onfocus="this.blur()"name="index"rel="history"onmouseout="this.className='nohover';"onmouseover="this.className='hover';"href="address">
我需要使用什么样的选择器?提前感谢。
What kind of selectors do I need to use to do this? Thanks in advance.
推荐答案
onmouseover="this.href = 'urlHere';"
或者使用jQuery,你可以使用类选择器。
Or using jQuery, you can use the class selector.
$('.nohover').hover(function(){
this.href = "urlHere";
});
而不是使用inline事件处理使用jQuery来管理它更好,试试这个。
Instead of having inline event handling use jQuery to manage it better, try this.
$('.nohover').hover(function(){
$(this)
.addClass('hover')
.removeClass('nohover')
.attr('href', 'urlHere');
}, function(){
$(this)
.addClass('nohover')
.removeClass('hover');
}).focus(function(){
$(this).blur();
});
这篇关于如何使用jQuery更改href属性onmouseover?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文