如何使用JQuery选择表中除表行中的最后一个文本框以外的所有文本框

编程入门 行业动态 更新时间:2024-10-27 12:39:54
本文介绍了如何使用JQuery选择表中除表行中的最后一个文本框以外的所有文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想向表中的每个文本框元素(每个行的最后一个文本框除外)添加一个向上键事件.该表在两个轴上都是动态的.

I want add a key up event to every text box element in a table excluding the last text box in each row. The table is dynamic on both axis.

向上键事件将对除最后一个文本框外的所有值进行总计.然后将总数放在该行的最后一个文本框中.

The key up event will total the values in all but the last text box. The total is then placed in the last text box for the row.

用于总计和设置总计的脚本都可以正常工作.

The script for the totaling and setting the total all works fine.

我厌倦了以下选择目标元素的过程:

I tired the following to select the target elements:

$("#Grid tr input:text:not(:last)").keyup(function(){ //do total stuff here })

不幸的是,它按文档所述工作,而不是我想要的那样,并且选中了最后一个复选框.

Unfortunately it works as documented and not as I wanted and selects all but the very last checkbox.

理想情况下,该解决方案不会涉及到下表示例中的任何进一步标记,也不会涉及任何循环.但是,如果那是需要的,那就这样吧.

Ideally the solution will not involve any further markup to the table example below or involve any looping. However if that is what it takes, so be it.

<table id="Grid"> <tr id="r1"> <td>Row 1</td> <td><input type="text" id="txt_a1_b1"></td> <td><input type="text" id="txt_a1_b2"></td> <td><input type="text" id="txt_a1_b3"></td> <td><input type="text" id="txt_a1_b4"></td> <td><input type="text" id="total_a1"></td> </tr> <tr id="r2"> <td>Row 2</td> <td><input type="text" id="txt_a2_b1"></td> <td><input type="text" id="txt_a2_b2"></td> <td><input type="text" id="txt_a2_b3"></td> <td><input type="text" id="txt_a2_b4"></td> <td><input type="text" id="total_a2"></td> </tr> <tr id="r3"> <td>Row 3</td> <td><input type="text" id="txt_a3_b1"></td> <td><input type="text" id="txt_a3_b2"></td> <td><input type="text" id="txt_a3_b3"></td> <td><input type="text" id="txt_a3_b4"></td> <td><input type="text" id="total_a3"></td> </tr> </table>

最后一点,合计文本框确实需要是一个文本框,因为还需要输入合计,然后将其在行中拆分,因此我不希望在合计文本框中使用向上键功能. /p>

One final point, the total text box does need to be a text box as there is also a requirement to enter a total then split it across the row and I do not want a key up function in the total text box.

推荐答案

我很惊讶没人能做到这一点:

I'm surprised noones quite got this yet:

$("#Grid tr :not(:last-child) :text").keyup(function(){ //do total stuff here })

更多推荐

如何使用JQuery选择表中除表行中的最后一个文本框以外的所有文本框

本文发布于:2023-10-28 13:52:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536810.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   如何使用   JQuery   表行中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!