如何在td元素上执行onclick时显示/隐藏div
我试图在表中点击<td>
来隐藏/显示div。表格包含两个<div>
s,并在点击主帐户持有人<td>
时应考虑显示第一个div,而其他div处于隐藏状态。对于授权重新订购,<td>
,应显示相应的div。如何在td元素上执行onclick时显示/隐藏div
我的HTML是
<div id="authreport">
<table width="270">
<tr>
<td>First name:</td>
</tr>
<tr>
<td>Last name:</td>
</tr>
<tr>
<td>Mobile phone:</td>
</tr>
<tr>
<td>Email:</td><td>
<tr>
<td>Password:</td>
</tr>
</table>
</div>
<div id="mainacc">
<table>
<tr>
<td colspan="2"><h3>Work details</h3></td>
</tr>
<tr>
<td>Organisation:</td>
</tr>
<tr>
<td>Industry Type:</td>
<tr>
<td>Street:</td>
</tr>
<tr>
<td>Postcode:</td>
</tr>
<tr>
<td>Country:</td>
</tr>
</table>
</div>
我的JavaScript是
function authorised_reporter(auth){
var button = document.getElementById('auth')
auth.onclick = function() {
var div = document.getElementById('authreport');
if (div.style.display !== 'none') {
div.style.display = 'none';
}
else {
div.style.display = 'block';
} }
};
任何一个可以给我如何做到这一点的想法?
你应该保持这个伟大的教程页面上的眼睛: http://www.w3schools.com/jquery/jquery_hide_show.asp。
W3School是一个很棒的教程网站(从我的角度来看是最好的),并且该页面向您展示了一个使用JQuery框架的示例,它是页面中的“必须包含”源代码,因为它提供了非常好的帮助常见的(也是更复杂的)Javascript函数。 http://jquery.com/ 。最好问候
[W3fools](http://w3fools.com/) – 2013-04-26 06:36:43
如果你使用JQuery,那很简单。
$('#DivID').click(function(){
//You can use show(), hide(), or toggle()
$('#DivID').toggle();
});
如果您浏览的jQuery API有很多,你可以使用像淡出和东西的影响。
谢谢你的回答,我已经解决了。 – user2086641 2013-12-03 07:00:54
哪个div被隐藏,哪个div被显示?你能改善你的问题吗? – Sandeep 2013-04-26 06:18:41