单击“提交”按钮获取表单名称

时间:2015-03-17 08:59:24

标签: javascript angularjs

    app.directive('customToaster', function () {

        return {
            link: function (scope, element, attrs, ctrl) {

                var foundButton = document.getElementByIds("buttonName2");    

                  foundButton.bind('click', function () {
                    scope.$apply(function () {
                      console.log('some text');
                    });
                });
              });
<form name="someName2">
 <div> 
  <div> 
   <button type="submit" name="buttonName2">Submit2 </button>
  </div>
 </div>
</form>

如何使用AngularJS点击提交按钮获取表单名称。

<form name="someName">
 <div> 
  <div> 
   <button type="submit">Submit </button>
  </div>
 </div>
</form>

请记住,嵌套div标签的数量可以多于两个。 谢谢!

1 个答案:

答案 0 :(得分:0)

    app.directive('customToaster', function () {

    return {
        link: function (scope, element, attrs, ctrl) {

                $scope.inputClick = function(name) {
                    console.log("form name: " + name);
                }
         }
    }
    });

<form ng-model="someName2">
<div> 
    <div> 
    <button ng-click="inputClick(someName2)" type="submit" name="buttonName2">Submit2 </button>
    </div>
</div>
</form>