javascript - 限制 'Add Row' 函数中添加的行数为 10

标签 javascript jquery

我在java脚本中有一个“添加行”功能。如何将添加的行数限制为不超过 10 行?这是我的代码。感谢您的帮助!

$(document).on('click', '#addAddOnDay', function() {
    var rowCount = $('#addOnDay tr').length + 1;
    var rowClass = (rowCount % 2 != 0) ? 'rowOdd' : 'rowEven';
    $('#addOnDay').append('<tr class="'+ rowClass +'"> \
<td align="center"><input type="text" class="text" style="width: 99%;" /></td> \
<td align="center"><input type="radio" name="4a_1"> <label>Yes</label> &nbsp; <input type="radio" name="4a_1" checked> <label>No</label></td> \
<td align="center">20000 or 95%</td> \
<td align="center" class="rollUpDisplay">1</td> \
</tr>');
});

最佳答案

$(document).on('click','#addAddOnDay',function(){

                var rowCount = $('#addOnDay tr').length; // current number of rows
                if(rowCount >= 10) {
                        return ;
                        }
   // Rest of the code....

                    });

关于javascript - 限制 'Add Row' 函数中添加的行数为 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18643274/

相关文章:

javascript - 是否可以在 Node js 中执行一组包括系统重启的步骤?

javascript - 如何为点阵打印机打印纯文本格式的页面?

javascript - 如何将输入字段定位在动态增长的表格下方

javascript - jQuery .data() 火狐浏览器

javascript 控制台未记录正确的循环值

javascript - 如何在 Node 5.6.0 环境中运行 Node 6 npm 包?

javascript - Rails 通过 ajax 渲染 View

javascript - 即使在 onload 之后,仍保持先前 jquery 全局变量的值不变

javascript - 在 List.js 中添加图片 src 和 <a> href

javascript - 滚动顶部不工作