简体   繁体   English

如何在对td元素执行onclick时显示/隐藏div

[英]how to show/hide a div while performing onclick on a td element

I am trying to hide/show a div while clicking <td> in a table. 我试图在单击表中的<td>时隐藏/显示div。 Table contains two <div> s, and consider while clicking main account holder <td> that the first div should be displayed and the other div is in hidden condition. 该表包含两个<div> ,并在单击主帐户持有人<td>考虑应显示第一个div,而另一个div处于隐藏状态。 For authorized reorder, <td> , the respective div should display. 对于授权的重新订购<td> ,应显示相应的div。

My HTML is 我的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>    

My JavaScript is 我的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';
  }  }
};

Can any one give me an idea of how to do this? 谁能给我一个方法的想法?

You should keep an eye on this great tutorial page : http://www.w3schools.com/jquery/jquery_hide_show.asp . 您应该关注这个很棒的教程页面: http : //www.w3schools.com/jquery/jquery_hide_show.asp

W3School is a great tutorial site (the best from my point of view), and this page show you an example using the JQuery Framework which is "A MUST HAVE INCLUDED" source in your page because it gives very good helper for common (and more complex) Javascript functions. W3School是一个很棒的教程网站(从我的角度来看,这是最好的),并且此页面向您展示了一个使用JQuery框架的示例,该示例在页面中是“必须包含”的源代码,因为它为通用(以及更多内容)提供了很好的帮助者复杂)的Javascript函数。 http://jquery.com/ .Best Regards http://jquery.com/最好的问候

If you use JQuery it is very simple. 如果使用JQuery,则非常简单。

$('#DivID').click(function(){
    //You can use show(), hide(), or toggle()        
    $('#DivID').toggle();
});

If you browse through the jquery API there are a lot of effects you can use like fadeout and stuff. 如果您浏览jquery API,则可以使用很多效果,例如淡出和填充。

If I understand you correctly, what you're trying to achieve is like accordion . 如果我对您的理解正确,那么您想要实现的目标就像accordion You might wanna see this. 您可能想看看这个。

http://jqueryui.com/accordion/ http://jqueryui.com/accordion/

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

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