Aar*_*Lee 7 html popup title onhover
我已经查看过以前的问题,但没有一个真的对我有用,我已经检查了谷歌,我发现的信息看起来很模糊,所以我想我会试试这里.
是否有人知道/或已经解决了悬停时显示标题标签的问题.我有一系列链接和图像将分配标题标签,但是,其中一些将显示最好不要在悬停时弹出的信息.
是否有一个全局函数可以用来将它应用于所有标题标签?一个例子如下:
<a href="service.php" title="services for cars" />
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我想禁用悬停时出现的"汽车服务"标题.
再次感谢.
Sha*_*ard 10
这应该可以正常禁用单个标题:
<a href="service.php" title="services for cars" onmouseover="this.title='';" />
Run Code Online (Sandbox Code Playgroud)
如果您之后需要标题,则可以恢复它:
<a href="service.php" title="services for cars" onmouseover="this.setAttribute('org_title', this.title'); this.title='';" onmouseout="this.title = this.getAttribute('org_title');" />
Run Code Online (Sandbox Code Playgroud)
这种方式不是通用的..要将它应用于所有锚点,有这样的JavaScript代码:
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");
};
}
};
Run Code Online (Sandbox Code Playgroud)
编辑:为更多标签应用相同(例如<img>)首先将代码的核心移动到一个函数:
function DisableToolTip(elements) {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
element.onmouseover = function() {
this.setAttribute("org_title", this.title);
this.title = "";
};
element.onmouseout = function() {
this.title = this.getAttribute("org_title");
};
}
}
Run Code Online (Sandbox Code Playgroud)
然后将代码更改为:
window.onload = function() {
var links = document.getElementsByTagName("a");
DisableToolTip(links);
var images = document.getElementsByTagName("img");
DisableToolTip(images);
};
Run Code Online (Sandbox Code Playgroud)
小智 9
如果您使用'title'标签的原因是Aria合规,请改用aria-label.
<a href="service.php" aria-label="services for cars" />
Run Code Online (Sandbox Code Playgroud)