我正在创建一个简单的工具提示插件,它将“标题”属性内容显示为工具提示文本。所以我想禁用显示工具提示的默认浏览器行为,因为我在div
中显示它。所以我使用了下面的代码,但这不起作用,我可以看到默认工具提示和我的工具提示在一起,默认工具提示与我的工具提示重叠。禁用工具提示文本表单链接
$("a").hover(function(e){
e.preventDefault();
});
我正在创建一个简单的工具提示插件,它将“标题”属性内容显示为工具提示文本。所以我想禁用显示工具提示的默认浏览器行为,因为我在div
中显示它。所以我使用了下面的代码,但这不起作用,我可以看到默认工具提示和我的工具提示在一起,默认工具提示与我的工具提示重叠。禁用工具提示文本表单链接
$("a").hover(function(e){
e.preventDefault();
});
你为什么不只是确保有在<a>
标签没有alt
和title
属性。
<a href="http://google.com" alt="Google!" title="Google!" />Goto Google</a>
更改 -
<a href="http://google.com" alt="Google!" />Goto Google</a>
因此,所有你需要做的就是运行要remvove上的默认提示行为的所有<a>
标签这个jQuery代码 -
$(".desiredElements").removeProp('alt').removeProp('title');
如果您想维护这些工具提示以供后期使用,应该将它们保存在$.data
对象中,并返回第二个悬停函数中的值,即“悬停”回调。
$('.desiredElements').hover(function() {
$thisCached = $(this);
$.data(this, 'title', $thisCached.attr('title'));
$thisCached.removeAttr('title').removeAttr('alt');
},function(){
$thisCached = $(this);
$thisCached.attr('title',$.data(this, 'title');
$thisCached.attr('alt',$.data(this, 'title');
});
这是最简单的方式来分配工具内容,没有任何方法来删除默认的工具提示?如果是这样,那么我将不得不考虑你的建议:) –
@www - 查看我的更新...您可以轻松地删除工具提示与jQuery ... – Lix
removeprop将删除“title”和“alt”的内容,我会没有任何东西可以显示在我的工具提示中。 –
为什么重新发明车轮朋友?试试这个。 http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/ – naveen