javascript - 如何使用表单数据打印值?

标签 javascript jquery html angularjs

我想使用 formdata.entries 函数打印表单数据值?原因是我有多个 ng-repeat。

<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>Coupon Code</th>
        </tr>
    </thead>

    <tbody>
        <tr ng-repeat="coupon in coupons" class="{'fadeOut' : coupon.done}">
            <td>{{coupon.title}} <span class="fa fa-close margin-left" ng-click="deletecoupon($index)"></span>
            </td>
        </tr>
    </tbody>
</table>

<div name="couponsFrm">
    <input type="text" name="newcoupon" ng-model="newcoupon" required />
    <button ng-disabled="couponsFrm.$invalid" ng-click="addcoupon()" class="btn btn-primary">Add Coupon</button>
</div>

这是 Controller

$scope.submitTrType = function(){
    var formData = new FormData("#my-form");
    console.log(formData);
    formData.append('key1', 'value1');
    formData.append('key2', 'value2');
    for(var pair of formData.entries()) {
        console.log(pair[0]+ ', '+ pair[1]); 
    }
}

最佳答案

试试这个:

for (var value of formData.values()) {
                alert(value);
           }

关于javascript - 如何使用表单数据打印值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45011264/

相关文章:

javascript - 在 Bootstrap 4 中,多个元素 slider (桌面屏幕上同时显示 3 个元素),当涉及到移动尺寸时,将它们一个一个地移动

javascript - Three.js 中一组共面点的最佳拟合矩形

javascript - 如何使用 CORS 实现 JavaScript Google Places API 请求

jquery - Drupal/jQuery/CSS::Wrap 单选按钮标签在 span 标签中?

javascript - 如何在 $.each(?

html - CSS 和 Bootstrap : Create a line that connects rows

javascript - 如何清除 HTML5 canvas 中的圆弧或圆?

JavaScript 设计模式 : What is a Concrete Factory?

javascript - Puppeteer:找不到选择器的节点 - iframe 中的登录模式

jquery - 如何使这个 JQuery 工作