简体   繁体   English

如何通过单击文本框jQuery使表格可见

[英]how to make visible table by clicking the textbox jquery

I've created a numpad inside the table and setted the table visible false. 我在表内创建了一个数字键盘,并将表设置为false。 I want to display the table after user clicked to the textbox. 我想在用户单击文本框后显示表格。 here is the code I wrote; 这是我写的代码;

<div id="divTable"> 
                <table align="center"  runat="server" id="numpadTable" visible="false">
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="1" OnClick="Button1_Click" CssClass="btnNumpad" /></td>
                <td class="auto-style2">
                    <asp:Button ID="Button2" runat="server" Text="2" OnClick="Button2_Click" CssClass="btnNumpad" /></td>
                <td>
                    <asp:Button ID="Button3" runat="server" Text="3" OnClick="Button3_Click" CssClass="btnNumpad" /></td>
            </tr></table></div>

textbox id= "numpadID"; 文本框ID =“ numpadID”;

I have found such codes to do that but I failed. 我已经找到了执行此操作的代码,但失败了。 For example; 例如;

<script>
$(document).ready(function() {
    $('#numpadID').live('click', function(event) {

        $('#numpadTable').toggle('show');

    });
});
</script>

It doesnt work. 它不起作用。 Any help? 有什么帮助吗?

Instead of live use 'on' 代替现场使用“开”

$(document).ready(function() {
    $('#numpadID').on('click', function(event) {

        $('#numpadTable').toggle('show');

    });
});

Update Use This :- 更新使用此:-

$(document).ready(function() {
    $('#numpadID').on('click', function(event) {

        $('#numpadTable').fadeIn();

    });
});

As you are using ASP.NET, numpadID is a server control(as you are using runat="server" ) you need to use Control.ClientID . 在使用ASP.NET时, numpadID是一个服务器控件(在使用runat="server" ),您需要使用Control.ClientID <%= numpadID.ClientID %> will Gets the control ID for HTML markup that is generated by ASP.NET. <%= numpadID.ClientID %>将获取由ASP.NET生成的HTML标记的控件ID。

Use 采用

$("#<%= numpadID.ClientID %>").on('click', function () {
    $("#<%= numpadTable.ClientID %>").toggle('show');
});

OR 要么

You can use ClientIDMode.Static mode then you can continue with your existing code. 您可以使用ClientIDMode.Static模式,然后可以继续使用现有代码。 However I will not recommend it. 但是,我不会推荐它。


As of jQuery 1.7 , the .live() method is deprecated. 从jQuery 1.7开始 ,不推荐使用.live()方法。 Use .on() to attach event handlers. 使用.on()附加事件处理程序。 Users of older versions of jQuery should use .delegate() in preference to .live() 较旧版本的jQuery的用户应优先使用.delegate()而不是.live()

You can use this code to show and hide the table. 您可以使用此代码显示和隐藏表。

$("#<%= numpadID.ClientID %>").focus(function () {
    $("#numpadTable").attr('visible','true');
});

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

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