简体   繁体   English

在点击的地方打开一个div

[英]Open a div at place clicked

I have a rather simple question but i can't seem to find an answer to it. 我有一个相当简单的问题,但我似乎找不到答案。 I want when i click on any place on web page a div is opened. 我想当我单击网页上的任何位置时打开div。 how can i accomplish that CSS style. 我该如何完成CSS样式。 My question is about the position of the div if i add this div inside a table and i want it to be opened each time i click on different rows. 我的问题是关于div的位置,如果我将此div添加到表中并且希望每次单击不同的行时都将其打开。 Thanks. 谢谢。

Hmmm try something like this: 嗯,尝试这样的事情:

<table>
<tr onclick="d=document.getElementById('myDiv');if(d.style.display=='block'){d.style.display='none';}else{d.style.display='block';}">
 <td><td>
</tr>
<tr onclick="d=document.getElementById('myDiv');if(d.style.display=='block'){d.style.display='none';}else{d.style.display='block';}">
 <td><td>
</tr>
</table>

<div id="myDiv" style="display:none">
STuff
</div>

There are better ways to do this.. Im not sure if the tr tag has an onclick handler but its worth a try. 有更好的方法。.我不确定tr标记是否具有onclick处理程序,但值得尝试。 You could use a javascript library like jquery or mootools . 您可以使用javascript库,例如jquerymootools

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM