【问题标题】:Update table row using JQuery with textbox checking and I need to check the textbox values使用带有文本框检查的 JQuery 更新表行,我需要检查文本框值
【发布时间】:2014-01-13 08:37:57
【问题描述】:

这是我的 JQuery,当按钮单击时,我在该表中附加了具有文本框的表行

我的html代码朋友

       <html>
        <head>
         </head>
         <body>
         <table>
           <tr>                
            <td>                    
                <label id="RecFrom">Receied From</label><br />
                <%: Html.TextBox("RecFrom", null, new { @class = "onlyname", id="RFrom" })%>
            </td>
            <td>
                <label id="RecDate" > Received Date </label><br />                    
                <%: Html.TextBox("RecDate", null, new { @class = "date", id="Rdate", @readonly = "readonly" })%>
            </td>
            <td id="External">
                <%: Html.Label("External Referance") %>
                <input type='text' id='Exref' name='ExternalReferance'>
            </td>                    
         </tr>
         <tr id="Refdetails">
            <td>
                <%: Html.Label("Referance Date") %>
                <input type='text' id='RefDate' class='date' readonly='readonly'>
            </td>
            <td>
                <%: Html.Label("Impact Of Payment") %>
                <select id='Impact' name='Impact' class='dropdown'><option>NO</option><option>YES</option></select>
            </td>
            <td>
                <%: Html.Label("Impact By Date") %>
                <input type='text' id='impactdate' name='Impactdate' class='date' readonly='readonly'>
            </td>   

        </tr>
        <tr>   
            <td id="Amountdetails">
                <%: Html.Label("Impact By Amount") %>
                <input type='text' id='Amount' name='ImpactAmount' class='Number'>
            </td>             
        </table>


   <table id="ProductRecipt">
     <tbody>
     <tbody>
    </table>
         <input type="Submit" value="Next" id="btn"/>
   </body>
 </html>

我的 JQuery 是

     $(document).ready(function ()
         $('#btn').click(function (){
             $('#ProductRecipt tbody').append("<tr><td class='code'>" + ItemCode + "<input type='hidden' name='ItemCode' value='" + ItemCode + "'/></td><td class='desc'>" + $('#Cat').val() + "<input type='hidden' name='ItemName' value='" + $('#Cat').val() + "'/></td><td class='qty'>" + $('#RFrom').val() + "<input type='hidden' name='ReceviedFrom' value='" + $('#RFrom').val() + "'/></td><td class='qty'>" + $('#Rdate').val() + "<input type='hidden' name='ReceviedDate' value='" + $('#Rdate').val() + "'/></td><td>" + result.Quantity + "<input type='hidden' class='TotalQuantity' value= '"+ result.Quantity +"'></td><td><input type='text' class='Rqty' name='ReceviedQuantity'></td><td><input type='text' name='Remarks' style='widht : 75px;'></td><td><input type='button' class='remove' value='remove'/></td></tr>");
           });
       $('#ProductRecipt tbody').on('focusout', '.Rqty', function () {
        var qty = $(this).parent($('#ProductRecipt tbody .TotalQuantity').val());
        alert(qty);
        var rqy = (this).val();
        alert(rqy);
        if (qty > rqy) {
            alert('Enter Minimum Quantity');
            return false;
            $(this).focus();
        }
      });
   });

【问题讨论】:

    标签: javascript jquery asp.net-mvc jquery-ui


    【解决方案1】:

    我认为这是你需要的:

    $(document).on("focusout", ".Rqty", function() {
        alert($(this).val());  // do the validation here
    });
    

    【讨论】:

    • 我有 2 个文本框,其中文本框的值正在获取
    • 重点突出的那个。例如,如果您单击文本框,然后单击 out 或按选项卡或以某种方式离开该框,它将触发事件。 $(this).val() - 代表文本框的值
    • 好的,那么如何比较同一行的值但另一个文本框值
    • 如果您在同一行中只有一个给定类的字段,您可以执行以下操作: var the_value_of_the_other_box = $(this).parents('tr').find('.your_class_name' ).val();警报(the_value_of_the_other_box);
    • 在 jQuery 上操作表格时不需要使用“tbody”选择器。这应该可以正常工作: $('#ProductRecipt').append('your_html_code');
    【解决方案2】:

    试试这个:

    $(document.body).on('mouseout', '#ProductRecipt tbody .Rqty', function() {
     var qty = $(this).parent($('.TotalQuantity').val());
        alert(qty);
        var rqy = ('.Rqty').val();
        if (qty > rqy) {
            alert('Enter Minimum Quantity');
            return false;
            $(this).focus();
    });
    

    【讨论】:

    • 朋友 document.body 意味着它可以获取所有表格主体标签,我是对的
    • 我已修改选择器。请立即查看
    • @Dinesh:如果你能创造一些小提琴会很棒
    • 如何创建小提琴朋友
    • 把你的代码放在jsfiddle.net。运行并检查输出。然后保存并提供链接。
    猜你喜欢
    • 2014-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    • 1970-01-01
    • 2012-12-06
    相关资源
    最近更新 更多