jquery文本框按键事件

时间:2011-09-18 02:10:38

标签: jquery

我真正想要做的是在表格的每个输入框上运行一个函数。该表有一个BudgetTable类,所以我虽然

$(".BudgetTable tr input:text").keypress...

会起作用,但在VS2010中断点没有击中。

所以我创建了一个简单的页面,以确保它不是标记,所以我可以在这里发布一些不太复杂的东西。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Budget.aspx.cs" Inherits="BudgetApplicationWeb.Budget" %>

<!DOCTYPE html PUBLIC "-//W3C//Dth XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/Dth/xhtml1-transitional.dth">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="Styles/BudgetGrid.css" rel="stylesheet" type="text/css" />
    <script  type="text/javascript">
    window.my_config = 
    { 
        last_section : "",
        current_section_row:0
    };

    $(document).ready(function () {
        $("tr").each(function (index, domElem) {
            var className = $(this).attr("class");
            if (className == window.my_config.last_section) {

                window.my_config.current_section_row++;

                if (window.my_config.current_section_row % 2 == 0) {
                    $(this).addClass("alt");
                }

            }
            else if (className != "") {
                window.my_config.last_section = className;
                window.my_config.current_section_row = 0;
                if (window.my_config.last_section.toString().substr(0, 6) == "DataTR") {
                    $(this).addClass("alt");
                }
            }
        });
    });

    $("input").keypress(function (event) {
        var className = $(this).attr("class");
        var str = "";

        str += "ClassName:" + className + "<BR>"
        str += "ParentItem:" + className.toString().replace("Item", "") + "<BR>"

        // $("#debug").text = str;
        $("#debug").text = "hello";
    });
    </script>
</head>
<body>
    <form id="form1" runat="server">   
    <div id="debug">
        <asp:TextBox ID="TextBox3" runat="server" />
    </div>
    </form>
</body>
</html>

我查看了帖子

How do I Select all text boxes in a table excluding the last one in the table row with JQuery

我无法弄清楚为什么按键无效。

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

我看到几个红旗

  1. 你没有在document.ready
  2. 中对此进行约束
  3. 文本框没有类,因此您的className行无效
  4. className.toString()是多余的
  5. 另外,您使用的是firebug吗?您是否看到任何控制台错误消息?

相关问题