如何将 Jquery 表单提交功能更改为 AngularJS 功能?

我有一个 JQuery 函数,如果我点击表单上的更新按钮,它就会触发。哪个有效。我打算将其更改为 Angular JS 指令。不知道该怎么做,我对 Angular JS 非常陌生。


我曾尝试以 Angular JS 的方式对其进行编码,但我不确定如何像使用 JQuery 那样将整个表单数据传递给函数。


这是html文件,


表单.HTML:


<form class="form-horizontal form-label-left input_mask" id="billingInfoForm" name="billingInfoForm">

  <div class="row">

    <div class="col-md-6 col-sm-6 col-xs-12 form-group has-feedback">

      <label class="control-label" for="firstName">First Name </label>

      <input type="text" data-recurly="first_name" class="form-control" id="firstName" name="firstName"

        ng-model="team.team_name">

    </div>


    <div class="col-md-6 col-sm-6 col-xs-12 form-group has-feedback">

      <label class="control-label" for="lastName">Last Name </label>

      <input type="text" class="form-control" id="lastName" name="lastName" data-recurly="last_name">

    </div>

  </div>


  <div class="row">

    <div class="col-md-4 col-sm-4 col-xs-12 form-group has-feedback">

      <label class="control-label" for="address1">Address</label>

      <input type="text" data-recurly="address1" class="form-control" id="address1" name="address1"

        ng-model="team.team_address.address1">

    </div>


    <div class="col-md-2 col-sm-2 col-xs-12 form-group has-feedback">

      <label class="control-label" for="city">City</label>

      <input type="text" class="form-control" id="city" name="city" data-recurly="city"

        ng-model="team.team_address.city">

    </div>


    <div class="col-md-2 col-sm-2 col-xs-12 form-group has-feedback">

      <label class="control-label" for="state">State <span class="required"></span></label>

      <input type="text" class="form-control" id="state" name="state" data-recurly="state"

        ng-model="team.team_address.region">

    </div>


猛跑小猪
浏览 157回答 1
1回答

斯蒂芬大帝

使用表单的元素,而不是字符串:$scope.update = function(event){&nbsp; //event.preventDefault();&nbsp; ̶v̶a̶r̶ ̶f̶o̶r̶m̶ ̶=̶ ̶'̶b̶i̶l̶l̶i̶n̶g̶I̶n̶f̶o̶F̶o̶r̶m̶'̶;̶&nbsp; var formEl = document.getElementById('billingInfoForm');&nbsp; var form = angular.element(formEl);&nbsp; recurly.token(form, function (err, token) {&nbsp; &nbsp; if (err) {&nbsp; &nbsp; &nbsp; console.log(err);&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; somefunction();&nbsp; &nbsp; &nbsp; form.submit();&nbsp; &nbsp; }&nbsp; });}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript