jquery对页面加载的影响

时间:2012-02-11 07:05:10

标签: jquery asp.net

我想使用jquery js在页面加载上隐藏div。然后点击一个按钮,我想显示该div。我甚至无法做到这么努力。 上面显示的是我的jquery函数和 我希望隐藏在页面加载上并显示在按钮点击事件上的Div。

<div id="newDiv">
            <fieldset class="fieldset">
                <legend>Add Salary Allounce Type:</legend>
                <table cellpadding="0" cellspacing="0" align="center" class="table">
                    <tr>
                        <td>
                            <asp:Label ID="LabelAllounceType" runat="server" Text="Allounce Type:"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="LabelAllounceType1" runat="server" Text="Allounce Type:"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </fieldset>
<asp:Button ID="ButtonAddNew" runat="server" Text="Add New Type" OnClientClick="" />`
        </div>
<script>
     $(document).ready(function () {
                $('#ButtonAddNew').click(function () {
                    $('#newDiv').hide();
                });

            }); 
</script>

2 个答案:

答案 0 :(得分:3)

好吧,你的代码说当你点击按钮时,应该隐藏div。你可能想要更像的东西:

$(document).ready( function () {
  $('#newDiv').hide(); // make sure the div is hidden on page load.  You could also
                       // accomplish this by making it have a style of display: none

  $('#buttonAddNew').click( function () { 
    // when the button is clicked, show the div.
    $('#newDiv').show(); 
  });
});

答案 1 :(得分:0)

你所要做的就是添加一个display:none;到您的div,然后以编程方式显示它。

<div id="newDiv">

更改为:

<div id="newDiv" style="display:none;">

然后在你的javascript中写道:

$('#ButtonAddNew').click(function(){
    $('#newDiv').css("display", "block");
});
相关问题