小编Ros*_*ose的帖子

避免使用jquery多次选择相同的选项

我有两个表Table1和Table2.每个表都包含<select>标记和选项,它们的值相同.

现在我想检查每个表,有多个选项存在多次.如果是,则已选择警报选项.

我的代码是:

$('#table1 tr').each(function() {
    $(this).find('select').change(function() { //alert($(this).val())
        if ($('option[value=' + $(this).val() + ']:selected').length > 1) {
            alert('option is already selected');
            $(this).val($(this).find("option:first").val());
        }
    });
});

$('#table2 tr').each(function() {
    $(this).find('select').change(function() { //alert($(this).val())
        if ($('option[value=' + $(this).val() + ']:selected').length > 1) {
            alert('option is already selected');
            $(this).val($(this).find("option:first").val());
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

当在第一个表和第二个表中选择相同时,它将提醒已选择的选项.我的代码出了什么问题?

你可以在这里测试代码.

html javascript jquery

11
推荐指数
1
解决办法
2175
查看次数

keyup上的文本字段的总和会导致行的第一个字段中出现问题

我有一个table.I我试图下面找出总和: td(1) + td(2) + td(3) = td(4),td(5) + td(6) + td(7) = td(8),td(9) + td(10) + td(11) = td(12).

这是我的代码:

$(document).ready(function () {
    $('#table').on('keyup', 'input', function () {
        $("#table tr").slice(2).find("td:nth-child(4n + 1)").each(function () {
            var sum = 0;
            $(this).prevAll(':lt(3)').find('input').each(function () {
                sum += (+this.value || 0)
            });
            $(this).find('input').val(sum)
        })
    })
})
Run Code Online (Sandbox Code Playgroud)

上面的代码工作正常.但我的问题是,我不能输入任何东西到第一列(即td:eq(0)).我的代码有什么问题?

http://jsfiddle.net/b0svwpnn/3/

html javascript jquery

5
推荐指数
1
解决办法
45
查看次数

css表示特定表的行和列

我有很多html表,其中一个被命名为"table1".我想只给这个表格风格.我用了:

#table1 tr,th,td
  {

   border: 5px solid black;
  }
Run Code Online (Sandbox Code Playgroud)

但是当它执行时,其他表的td , tr, th样式被设置为#table1与样式相同.

我怎样才能将Style赋予特定表格td , tr, th

html css jquery

3
推荐指数
1
解决办法
133
查看次数

标签 统计

html ×3

jquery ×3

javascript ×2

css ×1