JavaScript 隐藏显示
我正在尝试用 javascript 做一个简单的隐藏和显示功能(不是 Jquery,我想学习);是的,我还在学习。我想做的是 Facebook 和其他应用程序,当你将鼠标悬停在新闻提要文章上时,会显示一个小 X,可以作为删除该文章的选项。我试图在表格(表格单元格)上执行此操作,
这是我的标题函数:
function showHide(id) {
if(document.getDocumentById(id).style.visibility == 'hidden')
document.getDocumentById(id).style.visibility = 'visible';
else
document.getDocumentById(id).style.visibility = 'hidden';
}
在正文(php)中:
echo '<tr>';
echo '<td class="managealbum_delete" id="managealbum_delete'.$x.'">X</td>';
echo '<td>' . $album->title . '</td>';
echo '<td>' . $album->caption . '</td>';
echo '<td style="border: 1px solid black;" onMouseOver="showHide('."'".'managealbum_delete'.$x."'".');" onMouseOut="showHide('."'".'managealbum_delete'.$x."'".');">' . $album->media . '</td>';
echo '</tr>';
I'm trying to do a simple hide and show function in javascript (NOT Jquery please, I want to learn); and yes I'm still learning. What I'm trying to do is Facebook and other apps that when you hover on a news feed article, there's a small X that shows that serves as an option to delete that. I'm trying to do that on tables (table cell)
here's my header function:
function showHide(id) {
if(document.getDocumentById(id).style.visibility == 'hidden')
document.getDocumentById(id).style.visibility = 'visible';
else
document.getDocumentById(id).style.visibility = 'hidden';
}
and in the body (php):
echo '<tr>';
echo '<td class="managealbum_delete" id="managealbum_delete'.$x.'">X</td>';
echo '<td>' . $album->title . '</td>';
echo '<td>' . $album->caption . '</td>';
echo '<td style="border: 1px solid black;" onMouseOver="showHide('."'".'managealbum_delete'.$x."'".');" onMouseOut="showHide('."'".'managealbum_delete'.$x."'".');">' . $album->media . '</td>';
echo '</tr>';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该函数是
getElementById
,而不是getDocumentById
另外,您可以稍微缩短它,并检查以确保找到一个元素,如下所示:
The function is
getElementById
, notgetDocumentById
Also, you can shorten it a bit, and check to make sure an element was found like this:
好吧,如果您确实想隐藏它而不仅仅是删除其内容,您应该使用:
要显示它(TD),请使用:
http://www.w3schools.com/cssref/pr_class_display.asp
Well, if you really want to hide it and not just erase its content you should use:
And to show it (TDs), use:
http://www.w3schools.com/cssref/pr_class_display.asp