简体   繁体   English

使用JavaScript的网格中的金额不应小于0

[英]Amount should not be less than 0 in grid using javascript not working

When I go to Insert first record into the gridview . 当我去插入第一条记录到gridview What I want is, My Amount column should not be 0 or less than that. 我想要的是,“我的Amount列不应为0或小于0

Here is what my code looks like. 这是我的代码的样子。

function checkAgrmVal() {
        for (var i = 0; i < GridPayInfo.Rows.length; i++) {
            var AgrmntAmt = GridPayInfo.Rows[i].Cells[5].Value;
            alert(AgrmntAmt);
            if (AgrmntAmt <= "0") {
                alert('Agreement amount cannot be 0 or less than 0');
                return false;
            }
        }
    }

It doesn't works when I go to add the first row, but it does work when I go to add the second row. 当我添加第一行时,它不起作用,但是当我添加第二行时,它起作用。

  • To get table rows use GridPayInfo.rows[i].cells[5] not Rows and Cells 要获取表行,请使用GridPayInfo.rows[i].cells[5]而非RowsCells
  • To get Cell content use innerText , textContent to get text or innerHTML to get HTML not .Value . 要获取单元格内容,请使用innerTexttextContent来获取文本,或者使用innerHTML来获取HTML而不是.Value
  • .Value should be .value that works with input and textarea. .Value应该是可与输入和文本区域一起使用的.value

So Your example should work see below code: 因此,您的示例应该可以正常工作,请参见以下代码:

 function checkAgrmVal() { var GridPayInfo = document.getElementById("tbl"); for (var i = 0; i < GridPayInfo.rows.length; i++) { var AgrmntAmt = GridPayInfo.rows[i].cells[5].innerText; if (AgrmntAmt <= "0") { alert('Agreement amount cannot be 0 or less than 0 found in row: '+ (+i+1)); return false; } } } 
 <table id='tbl'> <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>-1</td></tr> <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>5</td></tr> <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>-3</td></tr> <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>-4</td></tr> <tr><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>3</td></tr> </table> <button onclick='checkAgrmVal()'>check</button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM