从输入文本中获取值然后提醒它

时间:2016-12-08 08:48:26

标签: jquery html ajax

我在DataGridTextColumn内尝试提醒值。

<td>
$(document).ready(function() {
  $('.edits').each(function(index) {
    $(this).change(function() {
      alert($(this).val());
    });
  });

})

确定。从上面我现在可以<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> <table width="200" border="1"> <tbody> <tr> <td width="40">2</td> <td width="144"> <input class="edits" type="text"> </td> </tr> <tr> <td>3</td> <td> <input class="edits" type="text"> </td> </tr> <tr> <td>5</td> <td> <input class="edits" type="text"> </td> </tr> </tbody> </table>了。但如果来自alert怎么办?如何提醒它?

append

这是我的HTML表格

function generateDetail(){
        var nilai = $("#poTrans").val();
         $.ajax({
                     url: '<?=base_url();?>bapb_mutasi/background_list_fa_detail/' + nilai,
                     dataType: 'JSON',
                     success: function(data) {
                        $.each(data, function(k, v) {
                                    $("#result").append('<tr>' +
                                                        '<td> </td> ' + 
                                                    '<td> '+v.TransactionNo+' </td>'+
                                                    '<td> '+v.LineNo+' </td>'+
                                                    '<td> '+v.ItemCode+' </td>'+
                                                    '<td> '+v.ItemName+' </td>'+
                                                    '<td> '+v.Quantity+' </td>'+
                                                    '<td> '+v.UOMCode+' </td>'+
                                                    '<td> '+v.QuantityConvertingRatio+' </td>'+
                                                    '<td class="base"> '+parseInt(v.BaseQuantity)+' </td>'+
                                                    '<td> '+parseInt(v.QuantityReceived)+' </td>'+
                                                    '<td class="edittbl">' +
                                                    '<input class="edits" type = "text" name = "quantityEdit"> </td>'+
                                                    '<td> '+v.BaseUOMCode+' </td>'+
                                                    '<td> '+v.ExtraRemark+' </td>'+
                                                    '<td> '+v.ExtraRemark2+' </td>'+
                                                    '</tr>'
                                                        );      
                                        $('.edits').val(v.QuantityEdit);                    
                             });

                    }    
            });

    }

结果示例

 <table width="631" id="bla" class="table table-bordered">
           <thead>
                <tr>
                    <td><strong> Document No </strong></td>
                    <td><strong> Transaction No </strong></td>
                    <td><strong> Line No </strong></td>
                    <td><strong> Item Code </strong></td>
                    <td><strong> Item Name </strong></td>
                    <td><strong> Quantity </strong></td>
                    <td><strong> UOM Code </strong></td>
                    <td><strong> Quantity Converting Ration </strong></td>
                    <td><strong> Base Quantity </strong></td>
                    <td><strong> Quantity Received </strong></td>
                    <td><strong> Quantity Edit </strong></td>
                    <td><strong> Base UOM Code </strong></td>
                    <td><strong> Extra Remark </strong></td>
                    <td><strong> Extra Remark 2 </strong></td>
                </tr>
           </thead>
           <tbody id="result">

           </tbody>
           </table>

我的问题只有当我试图提醒我在这里输入的内容时(来自 [{"DocumentNo":"","TransactionNo":"LPOD-CJ-AR1-1983","LineNo":1000,"ItemCode":"J101260012","ItemName":"DISPLAY RACK","Quantity":"6.00000000000000000000","UOMCode":"PCS","QuantityConvertingRatio":1,"BaseQuantity":"6.00000000000000000000","QuantityReceived":0,"QuantityEdit":"6.00000000000000000000","BaseUOMCode":"PCS","ExtraRemark":"","ExtraRemark2":"","UnitCost":"31999.99999999999600000000","UnitCostAfterPayable":"31999.99999999999600000000","BaseUnitCost":"31999.99999999999600000000","BaseUnitCostAfterPayable":"31999.99999999999600000000"," ":""},{"DocumentNo":"","TransactionNo":"LPOD-CJ-AR1-1984","LineNo":2000,"ItemCode":"URS150400001","ItemName":"RAISER","Quantity":"2.00000000000000000000","UOMCode":"PCS","QuantityConvertingRatio":1,"BaseQuantity":"2.00000000000000000000","QuantityReceived":0,"QuantityEdit":"2.00000000000000000000","BaseUOMCode":"PCS","ExtraRemark":"","ExtraRemark2":"","UnitCost":"88000.00000000000000000000","UnitCostAfterPayable":"88000.00000000000000000000","BaseUnitCost":"88000.00000000000000000000","BaseUnitCostAfterPayable":"88000.00000000000000000000"," ":""}]

appends

抱歉我的英语不好。

1 个答案:

答案 0 :(得分:4)

对于使用on()添加的所有动态行,您需要使用append(),如下所示。

$(document).ready(function() {

  $(document).on('change', '.edits', function(){
         alert($(this).val());
  });
});