Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery-如何选择特定的表行_Jquery_Tablerow - Fatal编程技术网

jquery-如何选择特定的表行

jquery-如何选择特定的表行,jquery,tablerow,Jquery,Tablerow,我有个问题。我可以动态创建多行。每行有2个。每个都有类,tdDebit和tdCredit <table id="tblAcctForm"> <tr> <td class="tdDebit"><input type="text" /></td> <td class="tdCredit"><input type="text" /></td> </tr> </table>

我有个问题。我可以动态创建多行。每行有2个
。每个
都有类,
tdDebit
tdCredit

<table id="tblAcctForm">
 <tr>
  <td class="tdDebit"><input type="text" /></td>
  <td class="tdCredit"><input type="text" /></td>
 </tr>
</table>
请在此处查看我的工作代码:

PS:在测试之前创建多行


请帮忙。提前感谢。

传递给
其他元素的值太一般:它选择页面上所有tr中的所有.tdDebit/.tdCredit中的所有输入

而是将与输入元素相关的直接值传递给它:

$(document).ready(function () {
  $("tr .tdDebit input").live("keyup", function()  {
    var toDisable = $(this).closest('tr').find('.tdCredit input');
    checkContent(this, toDisable);
  });

  $("tr .tdCredit input").live("keyup", function()  {
    var toDisable = $(this).closest('tr').find('.tdDebit input');
    checkContent(this, toDisable);
  });
});
更好的是,让它更通用:

$(document).ready(function () {
    $("tr input").live("keyup", function()  {
    var toDisable = $(this).closest('tr').find('input').not(this);
    checkContent(this, toDisable);
  });
});

传递给
其他元素的值太笼统:它选择页面上所有tr内的所有输入。tdDebit/.tdCredit在所有tr内

而是将与输入元素相关的直接值传递给它:

$(document).ready(function () {
  $("tr .tdDebit input").live("keyup", function()  {
    var toDisable = $(this).closest('tr').find('.tdCredit input');
    checkContent(this, toDisable);
  });

  $("tr .tdCredit input").live("keyup", function()  {
    var toDisable = $(this).closest('tr').find('.tdDebit input');
    checkContent(this, toDisable);
  });
});
更好的是,让它更通用:

$(document).ready(function () {
    $("tr input").live("keyup", function()  {
    var toDisable = $(this).closest('tr').find('input').not(this);
    checkContent(this, toDisable);
  });
});

这样就可以了。不再需要第二个参数

function checkContent (activeElem, otherElem) {
    var $input=$(activeElem), $otherInput=$input.parent().next().find('input');
        if ($.trim($input.val()) != "")
            $otherInput.attr("disabled", "disabled");
        else
           $otherInput.removeAttr("disabled");
}

演示:http://jsfiddle.net/pcmwg/1/

这样就可以了。不再需要第二个参数

function checkContent (activeElem, otherElem) {
    var $input=$(activeElem), $otherInput=$input.parent().next().find('input');
        if ($.trim($input.val()) != "")
            $otherInput.attr("disabled", "disabled");
        else
           $otherInput.removeAttr("disabled");
}

演示:http://jsfiddle.net/pcmwg/1/

此外,如果您使用的是jQuery 1.7或更高版本,请在
上使用us
而不是
live
:此外,如果您使用的是jQuery 1.7或更高版本,请在
上使用us
而不是
live