如何使用JQuery选择表中除表行中的最后一个文本框以外的所有文本框 [英] How do I Select all text boxes in a table excluding the last one in the table row with JQuery

查看:83
本文介绍了如何使用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选择表中除表行中的最后一个文本框以外的所有文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆