使用ENTER键提交表单在Angular中不起作用

时间:2015-01-22 06:57:43

标签: javascript angularjs forms

我有一个带有下拉列表的form,文本框和一个提交按钮。我可以使用ENTER密钥提交表单,只需将ng-keypress="addBookmarkOnEnter($event)添加到任何文本框即可。

但是,如果不在任何文本框中添加ng-keypress,我可以执行相同的任务吗?

这是我的form

<form>
   <div><input type="text" class="greyPhold" placeholder="http://" data-ng-model="bookmark.url" /></div>
   <div class="forSelect">
      <div class="selHead" data-ng-class="{hOpen: popup.dropdownStatus}">
         <button data-ng-click="toggleDropdown()"><span data-ng-bind="popup.selectedCategory"></span></button>
         <ul id="testDiv2" class="dropdownH">
            <li data-ng-repeat="category in categories track by $index" data-ng-click="selectCategory($index)">
               <div class="colony pull-left"><span>{{category.category_name}}</span></div>
               <div class="pull-right"><input type="radio" name="tag" /><label></label></div>
            </li>
         </ul>
      </div>
   </div>
   <div class="createColony">
      <input type="text" class="whitePholder" placeholder="Create a new colony" data-ng-model="bookmark.categoryName"/>
   </div>
   <div class="complete text-center"><button type="submit" class="done" data-ng-click="addBookmark()">Complete</button></div>
</form>

1 个答案:

答案 0 :(得分:0)

希望这段代码可以帮到你

<html>
  <head>
    <script src="angular.min.js"></script>
   <script src="ui-bootstrap.js"></script>
  </head>
  <body bgcolor="gray">
    <div id="container" ng-app='two_way' ng-controller="two_way_control" style="background-color:CCFF66">
<p style="padding:10px;">
          <h1 align="center">  Search Product </h1>
          </p>
<p align="center">
<form method="post">
 <input type="text" ng-model="searchText" placeholder="Enter a name here" required>
        <button ng-click="check(searchText)">Search</button>
</form>
</p>
       Search Item Name:  {{searchText}}
</div>
</body>
</html>

并使用控制器内的给定代码

$scope.check=function(searchText){};