Javascript 动态隐藏/显示a<;td>;使用JQuery

Javascript 动态隐藏/显示a<;td>;使用JQuery,javascript,php,jquery,css,Javascript,Php,Jquery,Css,使用PHP,我返回一个表,每个表的行包含3列。第三列有一个隐藏的信息图标,除非将鼠标悬停在上面。以下是生成此表的PHP代码片段: $contoutput = $contoutput . '<tr><td>' . $xleft[$i] . '</td><td>' . $xright[$i] . '</td><td class="hiddensourceicon" onMouseOver="showicon(this);">'

使用PHP,我返回一个表,每个表的行包含3列。第三列有一个隐藏的信息图标,除非将鼠标悬停在上面。以下是生成此表的PHP代码片段:

$contoutput = $contoutput . '<tr><td>' . $xleft[$i] . '</td><td>' . $xright[$i] . '</td><td class="hiddensourceicon" onMouseOver="showicon(this);">' . findsource($xsource[$i]) . '</td></tr>';

但是由于某种原因,JQuery函数拒绝触发。我做错了什么?

隐藏后要再次显示它,您需要设置display:block否则它不会显示,因为您使用的是jquery,您可以使用.hide()和.show()方法ref-

隐藏后要再次显示它,您需要设置display:block否则它不会显示,因为您使用的是jquery,您可以使用.hide()和.show()方法参考-

尝试以下方法:

<?php
$contoutput = $contoutput . '<table cellspacing="5"><tr><td>' . "11" . '</td><td>' . "2222" . '</td><td id="xyz"  onMouseOver="showicon(this.id);"><span class="hiddensourceicon" >' . "hiiiii" . '</span></td></tr></table>';
echo $contoutput;
?>
<style>
.hiddensourceicon { display: none; }
</style>
<script>
function showicon(row2show){
var abc = "#"+row2show+" span";

$(abc).removeClass("hiddensourceicon"); }
</script>

.hiddensourceicon{display:none;}
功能显示图标(第2行显示){
var abc=“#”+row2show+“span”;
$(abc).removeClass(“hiddensourceicon”);}
试试这个:

<?php
$contoutput = $contoutput . '<table cellspacing="5"><tr><td>' . "11" . '</td><td>' . "2222" . '</td><td id="xyz"  onMouseOver="showicon(this.id);"><span class="hiddensourceicon" >' . "hiiiii" . '</span></td></tr></table>';
echo $contoutput;
?>
<style>
.hiddensourceicon { display: none; }
</style>
<script>
function showicon(row2show){
var abc = "#"+row2show+" span";

$(abc).removeClass("hiddensourceicon"); }
</script>

.hiddensourceicon{display:none;}
功能显示图标(第2行显示){
var abc=“#”+row2show+“span”;
$(abc).removeClass(“hiddensourceicon”);}

您在当前问题中将遇到的一个问题:
hiddensourceicon
设置为
display:none
,因此没有悬停的内容。如果将其设置为
opacity:0
,则它仍然可以悬停在上面。另外,
opacity
可以设置动画-这可能需要也可能不需要

下面是一种方法,也许其他人会有更有效的方法:

jQuery:

$( ".hiddensourceicon" ).hover(function() {
  $(this).toggleClass('show');
});

您在当前问题中将遇到一个问题:
hiddensourceicon
设置为
display:none
,因此没有悬停的内容。如果将其设置为
opacity:0
,则它仍然可以悬停在上面。另外,
opacity
可以设置动画-这可能需要也可能不需要

下面是一种方法,也许其他人会有更有效的方法:

jQuery:

$( ".hiddensourceicon" ).hover(function() {
  $(this).toggleClass('show');
});

它认为当你将某个东西设置为“无显示”,并试图在某个不存在的东西上悬停时,麻烦就来了。解决这个问题的一种方法是使用不透明度而不是显示。如果你想继续使用display,你必须考虑到屏幕上有什么东西可以悬停。下面是一个使用不透明度的快速解决方案

JSFiddle:

您还应该避免使用内联javascript。 例如mouseover=“function(args);”

var$hiddenicon=$('.hiddenicon');
$hiddenicon.on('mouseover mouseout',function(){
var opacity=$(this.css('opacity')==1?0:1;
$(this.css)({
不透明度:不透明度
});
});
表格,
th,
运输署{
边框:1px纯黑;
}
希德尼孔先生{
不透明度:0;
}

偶像
这里的东西
这里还有其他东西吗
偶像
这里的东西
这里还有其他东西吗
偶像
这里的东西
这里还有其他东西吗

它认为当您将某个内容设置为“无显示”,并试图将鼠标悬停在不存在的内容上时会出现问题。解决此问题的一种方法是使用不透明度而不是显示。如果你想继续使用display,你必须考虑到屏幕上有什么东西可以悬停。下面是一个使用不透明度的快速解决方案

JSFiddle:

您还应该避免使用内联javascript。 例如mouseover=“function(args);”

var$hiddenicon=$('.hiddenicon');
$hiddenicon.on('mouseover mouseout',function(){
var opacity=$(this.css('opacity')==1?0:1;
$(this.css)({
不透明度:不透明度
});
});
表格,
th,
运输署{
边框:1px纯黑;
}
希德尼孔先生{
不透明度:0;
}

偶像
这里的东西
这里还有其他东西吗
偶像
这里的东西
这里还有其他东西吗
偶像
这里的东西
这里还有其他东西吗

您可以发布触发功能代码吗?如何在隐藏td上获取鼠标悬停事件?您可以发布触发功能代码吗?如何在隐藏td上获取鼠标悬停事件?
$( ".hiddensourceicon" ).hover(function() {
  $(this).toggleClass('show');
});