我真正想要做的是在表格中的每個輸入框上運行一個函數。該表有一個類BudgetTable所以我雖然jquery text box keypress event
$(".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
我想不通爲什麼按鍵不工作。
感謝您的幫助
嘗試在輸入前添加一個冒號,讓你有$(「:input」)。按鍵.. – Ben
似乎沒有做任何事情。我認爲:是爲類型或過濾器像奇數甚至不是元素? – Mike