Javascript 仅保留行时禁用按钮
我有下面的脚本,我试图禁用删除,上移和下移按钮,如果只有一行存在。有人能告诉我怎么做吗,我卡住了 有人能告诉我如何使用下面的纸条向选择字段添加增量名称吗? 多谢各位Javascript 仅保留行时禁用按钮,javascript,jquery,row,Javascript,Jquery,Row,我有下面的脚本,我试图禁用删除,上移和下移按钮,如果只有一行存在。有人能告诉我怎么做吗,我卡住了 有人能告诉我如何使用下面的纸条向选择字段添加增量名称吗? 多谢各位 <script> $('.addnew').live('click', function(){ var thisRow = $(this).parent().parent(); newRow = thisRow.clone(true).insertAfter(thisRow); newRow.find('input:no
<script>
$('.addnew').live('click', function(){
var thisRow = $(this).parent().parent();
newRow = thisRow.clone(true).insertAfter(thisRow);
newRow.find('input:not(.add)').val("");
newRow.find('.remove').show();
newRow.find('input.increment').val(parseInt(thisRow.find('input.increment').val())+1);
});
$('.remove').live('click', function(){
$(this).parent().parent().remove();
});
$('.up,.down').click(function () {
var row = $(this).parents('tr:first');
if ($(this).is('.up')) {
row.insertBefore(row.prev());
}
else {
row.insertAfter(row.next());
}
});
</script>
这是另一个答案: 使用选择器选择所有行并获取长度 var rowCount=$'myTable tr'。长度 我不知道您的HTML是什么样子的,但是通过选择上面的行: var rowCount=$this.parents'tr'.length
因此,仅当该长度等于1时,才执行代码以禁用按钮。请注意,它将计算每个嵌套表的所有TR,因此您可能需要检查除1以外的其他数字。您可能需要使用.on而不是.live,因为在jQuery 1.7版中不推荐使用live。感谢您为我指明了正确的方向;虽然我尝试了你的解决方案,但没有成功。但是我成功地实现了这个=var rowCount=$this.closesttr.prevAlltr.length//如果rowcount>0/则获取表行//保留起始行