Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript/jquery从鼠标悬停时的链接隐藏标题属性_Javascript_Jquery - Fatal编程技术网

使用javascript/jquery从鼠标悬停时的链接隐藏标题属性

使用javascript/jquery从鼠标悬停时的链接隐藏标题属性,javascript,jquery,Javascript,Jquery,我在所有链接中使用title属性,但我不想在鼠标悬停时可见,但在屏幕阅读器的代码中仍然可见 var links = document.getElementsByTagName('a'); for (var i = 0; i < links.length; i++) { if (links[i].className == 'suppress') { links[i]._title = links[i].title; links[i].onmouseover = fu

我在所有链接中使用title属性,但我不想在鼠标悬停时可见,但在屏幕阅读器的代码中仍然可见

var links = document.getElementsByTagName('a');

for (var i = 0; i < links.length; i++) {
    if (links[i].className == 'suppress') {
    links[i]._title = links[i].title;
    links[i].onmouseover = function() { 
    this.title = '';
}

links[i].onmouseout = function() { 
    this.title = this._title;
}
var links=document.getElementsByTagName('a');
对于(变量i=0;i
因为您使用的是jQuery,所以可以用一种简单的方法来实现:

$(document).ready(function(){
    $("a").removeAttr("title");
});
或者,将其设置为空值:

$(document).ready(function(){
    $("a").attr("title", "");
});
如果这将改变屏幕阅读器的阅读方式,那么,你可以将目标锁定在悬停状态

$(document).ready(function(){
    $("a").hover(function(){
        $(this).attr("rel", $(this).attr("title"));
        $(this).removeAttr("title");
    }, function(){
        $(this).attr("title", $(this).attr("rel"));
        $(this).removeAttr("rel");
    });
});

因为您使用的是jQuery,所以可以用一种简单的方法来实现:

$(document).ready(function(){
    $("a").removeAttr("title");
});
或者,将其设置为空值:

$(document).ready(function(){
    $("a").attr("title", "");
});
如果这将改变屏幕阅读器的阅读方式,那么,你可以将目标锁定在悬停状态

$(document).ready(function(){
    $("a").hover(function(){
        $(this).attr("rel", $(this).attr("title"));
        $(this).removeAttr("title");
    }, function(){
        $(this).attr("title", $(this).attr("rel"));
        $(this).removeAttr("rel");
    });
});

使用jQuery,您可以在悬停时隐藏
标题
属性,并在鼠标移出时替换它:

$(function(){

    $('a').hover(function(e){

        $(this).attr('data-title', $(this).attr('title'));
        $(this).removeAttr('title');

    },
    function(e){

        $(this).attr('title', $(this).attr('data-title'));

    });​

});

与使用jQuery的.

类似,您可以在悬停时隐藏
标题
属性,并在鼠标悬停时替换它:

$(function(){

    $('a').hover(function(e){

        $(this).attr('data-title', $(this).attr('title'));
        $(this).removeAttr('title');

    },
    function(e){

        $(this).attr('title', $(this).attr('data-title'));

    });​

});

例如。

我试图在CSS中创建一个气泡工具提示,但是浏览器工具提示总是会出现,并且会把事情弄得一团糟。因此,像您一样,我需要禁用默认工具提示

我使用了一点JQuery来删除“Title”标记,但只在鼠标悬停时才删除。鼠标一出,“Title”标记就会恢复

以下是包含一些“标题”内容的DIV:

以下是完整示例的链接:


我试图在CSS中创建一个气泡工具提示,但是浏览器工具提示总是会出现,并且会把事情搞得一团糟。因此,像您一样,我需要禁用默认工具提示

我使用了一点JQuery来删除“Title”标记,但只在鼠标悬停时才删除。鼠标一出,“Title”标记就会恢复

以下是包含一些“标题”内容的DIV:

以下是完整示例的链接:

$(“.element”).hover(函数(){

$(“.element”)。单击(function(){//在我们离开该元素时激发

    // Retrieve the title from the temporary attribute
    var title = $(this).attr("tmp_title");

    // Return the title to what it was
    $(this).attr("title", title);

});
$(“.element”).hover(函数(){

$(“.element”)。单击(function(){//在我们离开该元素时激发

    // Retrieve the title from the temporary attribute
    var title = $(this).attr("tmp_title");

    // Return the title to what it was
    $(this).attr("title", title);

});


您使用的是jQuery,为什么要使用这么长的代码?它可能非常简单!与为什么不希望为用户提供工具提示完全相同?如果有相关数据,请向他们显示-屏幕阅读器和视觉浏览器;否则根本不使用标题属性。您使用的是jQuery,为什么要使用这么长的代码?可能非常简单!完全相同你为什么不想为你的用户提供工具提示呢?如果有相关的数据,就向他们展示——包括屏幕阅读器和视觉浏览器;否则就根本不使用标题属性。他说“在屏幕阅读器的代码中仍然可见”。删除后屏幕阅读器还能读取吗?嗯……是的,几秒钟后会更改代码并更新答案。:
rel
用于存储链接关系,而不是自定义数据:更好地使用
数据。他说“在屏幕阅读器的代码中仍然可见”.删除后屏幕阅读器还能读取吗?嗯……是的,几秒钟后会更改代码并更新答案。:)
rel
用于存储链接关系,而不是自定义数据:最好使用
数据。您使用的浏览器是什么?在OS X Chrome.ie9、Chrome 22.0.1229.79 m版、firefox15.0.1中工作正常?您是否尝试过小提琴?如果您尝试使用它,请确保在页面中包含jQuery库并将代码包装在
$(函数(){…})
wrapper-查看我的编辑。非常感谢,我更新了jquery版本,它工作得很好。您使用的浏览器是什么?在OS X Chrome.ie9、Chrome 22.0.1229.79 m、firefox15.0.1中工作得很好。您尝试过小提琴吗?如果您正在尝试,请确保在页面中包含jquery库,并将代码包装在
$(函数(){…};
wrapper-请看我的编辑。非常感谢,我更新了jquery版本,它工作得很好。请正确设置代码格式并对答案进行解释。请正确设置代码格式并对答案进行解释