有链接,
<a href="/video/?index=4/multimedia-layover.png" title="This is title"></div></a>
我想压制工具提示。
我已经审阅了这个question。我正在尝试做一些事情,比如将其添加到链接
onmouseover="title='';"
它正在工作但是,当我要点击该链接并想要处理该标题时,它显示空字符串,因为我使用了onmouseover="title='';"
是否有其他方法可以禁用工具提示?
只想禁用工具提示,不要将标题设为空。
答案 0 :(得分:1)
删除时将标题存储在另一个属性中。请尝试:
window.onload = function() {
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
var link = links[i];
link.onmouseover = function() {
this.setAttribute("org_title", this.title);
this.title = "";
};
link.onmouseout = function() {
this.title = this.getAttribute("org_title");
};
}
};
答案 1 :(得分:1)
或者通过jQuery:
$('a[title]').each(function(idx, anchor) {
var $anchor = $(anchor);
$anchor.attr('data-title', $anchor.attr('title')).removeAttr('title');
});
不是我不会将链接重置回propper功能。您还可以通过添加类来扩展[title]部分,例如.no-tooltip(因此:[title] .no-tooltip)。这将删除具有TITLE属性AND且具有no-tooltip类的所有锚标记上的标题。
答案 2 :(得分:0)
我的解决方案类似于Milind上面的回答,但使用的是jQuery。
jQuery(document).ready(function() {
jQuery("a[rel]").each(function() {
var saveAlt = jQuery(this).attr('alt');
var saveTitle = jQuery(this).attr('title');
jQuery(this).mouseenter(function() {
jQuery(this).attr('title', '');
jQuery(this).attr('alt', '');
});
jQuery(this).mouseleave(function() {
jQuery(this).attr('alt', saveAlt);
jQuery(this).attr('title', saveTitle);
});
jQuery(this).click(function() {
jQuery(this).attr('alt', saveAlt);
jQuery(this).attr('title', saveTitle);
});
});
});
您必须根据您的要求更改jQuery选择器。我希望这适用于LightBox和qTip2,你必须在这里禁止默认工具提示,但允许LightBox在显示更大的图像时显示图像标题。
尝试使用Chrome,IE和Firefox。