Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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-使工具提示获得2个img alt_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript jQuery-使工具提示获得2个img alt

Javascript jQuery-使工具提示获得2个img alt,javascript,jquery,html,css,Javascript,Jquery,Html,Css,假设我想在表格标题中使用图像 每个图像都为其指定了alt 如何使jQuery代码以行和列的alt显示工具提示?(行:列格式) 现在看起来是这样的: 代码: 那么这个呢: $('td').each(function () { var myIndex = $(this).index() + 1; //I took the first sibling th, and took its alt attribute var myTitle += $(this).siblings

假设我想在表格标题中使用图像

每个图像都为其指定了alt

如何使jQuery代码以行和列的alt显示工具提示?(行:列格式)

现在看起来是这样的:

代码:

那么这个呢:

$('td').each(function () {
    var myIndex = $(this).index() + 1;

    //I took the first sibling th, and took its alt attribute
    var myTitle += $(this).siblings('th').children("img").attr("alt");
    myTitle += ":";
    myTitle += $('tr:first-child th:nth-child(' + myIndex + ')').children("img").attr("alt");
    $(this).attr('title', myTitle);

    $(this).tooltip({
        show: false,
        hide: false
    });
});

好的,最简单的方法是将title元素留空。 已在页面上的隐藏div内生成内容。 然后在jQuery中初始化工具提示时,提供隐藏帮助内容的id

第一步

<div title=''  id="x">Show tool tip over this element</div>

@谢谢你的反馈!你最好发表你对这个问题的评论,因为更多的是关于这个问题本身,而且OP会收到你的评论;)你说得对,修好了。“不错的解决方案”仍然适合你:)这太棒了!谢谢您不应该在整个表中使用,只应在标题行中使用。这使得样式和JavaScript都变得更容易。其中还可以包括和元素。此外,还缺少结束标记。但你在尝试自己时做得很好:)
<div title=''  id="x">Show tool tip over this element</div>
<div style="visibility:hidden"> 
<div id="y">What ever the content you want to be shown as tool tip</div> 
</div>
$( "#x" ).tooltip({ track: true, content:function() {  return $( '#y' ).html(); } });