Jquery表中的隐藏字段

发布于 2024-07-16 13:17:29 字数 615 浏览 6 评论 0原文

我想知道是否有人知道使用 jquery 访问表行中的隐藏字段(通过客户端 ID)的方法。

$("#tblOne").find("tr").click(function() {
            var worker = $(this).find(":input").val();
        });

我发现上述内容适用于只有一个输入的行,但我需要一些帮助来找出一种通过输入名称获取值的方法。

这是表行的示例。 我如何通过 id 访问这两个字段?

<table id="tblOne">
<tr>
<td>
    <asp:HiddenField id="hdnfld_Id" Text='<% Eval("ID") %>'></asp:HiddenField>
</td>
<td>
    <asp:HiddenField id="hdnfld_Id2" Text='<% Eval("ID2") %>'></asp:HiddenField>
</td>
</tr> 
</table>

I was wondering if anyone knew of a way to access a hidden field (by client id) within a table row using jquery.

$("#tblOne").find("tr").click(function() {
            var worker = $(this).find(":input").val();
        });

I find that the above works for a row that has only one input, but I need some help figuring out a way to get the value by the inputs name.

Here's the example of a table row. How would I access the two fields by their id's?

<table id="tblOne">
<tr>
<td>
    <asp:HiddenField id="hdnfld_Id" Text='<% Eval("ID") %>'></asp:HiddenField>
</td>
<td>
    <asp:HiddenField id="hdnfld_Id2" Text='<% Eval("ID2") %>'></asp:HiddenField>
</td>
</tr> 
</table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

墨小墨 2024-07-23 13:17:29

我通常使用正向查找来匹配 id,此方法避免需要客户端 id

(id 包含 foo)
$(this).find("input[id*='foo']").val();

I normally use a positive lookup to match the id, this method avoids requiring the client id

(id contains foo)
$(this).find("input[id*='foo']").val();

羅雙樹 2024-07-23 13:17:29

按照您现在的设置方式,您可以执行以下操作:

$('tr td', '#tblOne').eq(0).find(':input').val(); // find input in 1st TD
$('tr td', '#tblOne').eq(1).find(':input').val(); // find input in 2nd TD

使用此功能,您不必担心输入的 ClientID。

With the way you have it setup right now, you could do this:

$('tr td', '#tblOne').eq(0).find(':input').val(); // find input in 1st TD
$('tr td', '#tblOne').eq(1).find(':input').val(); // find input in 2nd TD

Using this you don't have to worry about the input's ClientID.

二智少女猫性小仙女 2024-07-23 13:17:29

您可以这样做:

    $("#tblOne").find("tr").click(function() {
        var election = $(this).find("td").eq(0).html();
        var worker = $(this).find('input[name=theName]').val();
    });

阅读这篇优秀的文章 '如何使用 jQuery 得到你想要的东西'作者:Benjamin Sterling。

You could do it like this:

    $("#tblOne").find("tr").click(function() {
        var election = $(this).find("td").eq(0).html();
        var worker = $(this).find('input[name=theName]').val();
    });

Read through this excellent article 'How to get what you want using jQuery' by Benjamin Sterling.

⊕婉儿 2024-07-23 13:17:29

你为什么不简单地使用这个:

jQuery("#<%=hdnfld_Id.ClientID%>")

Why don't you simply use this:

jQuery("#<%=hdnfld_Id.ClientID%>")
千秋岁 2024-07-23 13:17:29

生成一个 不是吗? 你为什么不这么做呢

$("#foo").val()

我认为你需要更好地解释一下你想做什么。 如果您发现

$(this).find(":input").val();

...仅在您有一个输入时才有效,也许您正在寻找的是这样的:

$(this).find(":input").each(function() {
  // Prints the value of each input.
  alert($(this).val());
}

但就目前情况而言,您的问题不是很清楚。 尝试编辑您的问题并花点时间准确解释您想要的内容。

<asp:HiddenField id="foo"> generates an <input type="hidden" id="foo"/> does it not? Why don't you just do

$("#foo").val()

?

I think you need to explain what you're trying to do a bit better. If you find that

$(this).find(":input").val();

... only works when you have one input, maybe what you're looking for is this:

$(this).find(":input").each(function() {
  // Prints the value of each input.
  alert($(this).val());
}

But as it stands, your question is not very clear. Try editing your question and take your time to explain exactly what you want.

数理化全能战士 2024-07-23 13:17:29

不是答案,但我在从表格单元格中提取隐藏字段值时遇到了难以置信的困难(当然使用该表格上的表格排序器),所以我很高兴找到这行代码:

$(this).find (":输入").val();

而且效果非常好。

我还使用“.live”功能,因此即使在巨大的桌子上也可以使用。

谢谢你!!!

归属地LR

Not an answer, but I was having incredible difficulty in pulling a hidden field value from within a table cell (using tablesorter on that table of course), so I am so happy to have found this line of code:

$(this).find(":input").val();

and it works wonderfully.

I also use the ".live" function, so it works even on huge tables.

THANK YOU!!!

HLR

唯憾梦倾城 2024-07-23 13:17:29

我有三个选项卡,每个选项卡都有一个“提交”按钮,导致回发。 在提交按钮的单击事件之后,我希望当前选项卡保留。

步骤 1.

在选项卡 div 中添加一个 asp:HiddenField (“选项卡”div 包含包含我的选项卡内容的所有三个 div)。

<asp:HiddenField ID="sel_tab" Value="" runat="server" />

步骤 2.

使用导致回发的每个按钮的单击事件更新 sel_tab 的值。

protected void cmdSaveDailyMeasure_Click(object sender, EventArgs e)
{
    sel_tab.Value = "0";
}
protected void cmdSaveWeeklyMeasure_Click(object sender, EventArgs e)
{
    sel_tab.Value = "1";
}
protected void cmdSaveMonthlyMeasure_Click(object sender, EventArgs e)
{
    sel_tab.Value = "2";
}

步骤 3.
在我的 .js 文件中,我有以下代码

// Tabs
$(document).ready(function() {
    var iSelectedTab = $(this).find("input[id*='sel_tab']").val();
    if (iSelectedTab == null)
        iSelectedTab = 0;    
    $('[id$=tabs]').tabs({ selected: iSelectedTab });
});

即使您使用母版页(我是),它也可以工作。 不需要 <%=foo.ClientID%> 部分。

I have three tabs each with a Submit button causing post backs. After the click event for the submit button, I want the current tab to persist.

Step 1.

Added an asp:HiddenField inside the tabs div ('tabs' div holds all the three divs that have the content for my tabs).

<asp:HiddenField ID="sel_tab" Value="" runat="server" />

Step 2.

Updated the value of sel_tab with the click event of each button that causes a post back.

protected void cmdSaveDailyMeasure_Click(object sender, EventArgs e)
{
    sel_tab.Value = "0";
}
protected void cmdSaveWeeklyMeasure_Click(object sender, EventArgs e)
{
    sel_tab.Value = "1";
}
protected void cmdSaveMonthlyMeasure_Click(object sender, EventArgs e)
{
    sel_tab.Value = "2";
}

Step 3.
In my .js file I have the following code

// Tabs
$(document).ready(function() {
    var iSelectedTab = $(this).find("input[id*='sel_tab']").val();
    if (iSelectedTab == null)
        iSelectedTab = 0;    
    $('[id$=tabs]').tabs({ selected: iSelectedTab });
});

This works even if you are using Master Pages (i am). Don't need the <%=foo.ClientID%> part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文