首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery动态生成的表行,带有select选项上的输入字段验证

jQuery动态生成的表行,带有select选项上的输入字段验证
EN

Stack Overflow用户
提问于 2013-09-30 04:51:26
回答 1查看 777关注 0票数 2

我需要一些帮助在jQuery生成的具有输入字段和选择选项的动态表格行。

我希望当我选择选项js时,输入字段id fee-2将被禁用,当我选择选项php输入字段id fee-1时,将被禁用,以此类推,在不同的行上插入更多的行,不同于select选项。最后,需要通过字段id fee-1插入所有行中的一些行

示例如图所示

我的小提琴演示在这里

http://fiddle.jshell.net/softfiddle/cSbbK/2/

谢谢

EN

回答 1

Stack Overflow用户

发布于 2013-09-30 05:04:20

将HTML更改为:

代码语言:javascript
复制
<td><input type="text" id="fee-1" class="fee" name="js-fee"></td>
<td><input type="text" id="fee-2" class="fee" name="php-fee"></td>

然后使用这个Javascript:

代码语言:javascript
复制
$("#mytable").on("change", "select", function() {
    var feeid = "#fee-" + $(this).val(); // Get ID of DIV related to selected item
    $(".fee").prop('disabled', true); // Disable all the other DIVs
    $(feeid).prop('disabled', false); // Enable the related DIV
    // Now calculate the total
    var total = 0;
    $(".fee").each(function() {
        total += parseInt($(this).text(), 10);
    });
    // And display it somewhere
    $("#totaldiv").text(total);
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19083144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档