按Enter键时Angularjs默认操作

时间:2022-04-19 20:11:13

My understanding with forms, is that if the form has an ng-submit action associated with it, then pressing the Enter key would invoke that action, typically mimicking the click of the form's "submit" button. I have a form that does not have have a button, but a custom image of a button within a div tag and the div tag has the ng-click action. When I press Enter, nothing happens. What am I missing?

我对表单的理解是,如果表单有与之关联的ng-submit操作,则按Enter键将调用该操作,通常模仿单击表单的“提交”按钮。我有一个没有按钮的表单,但div标签中的按钮的自定义图像和div标签具有ng-click操作。当我按Enter键时,没有任何反应。我错过了什么?

2 个解决方案

#1


10  

Make your button type submit and add a class attribute and style your button to make it an image like:

让您的按钮类型提交并添加一个类属性并设置您的按钮样式,使其成为如下图像:

<form ng-submit="someAction()">
 <button type="submit" class="submitbutton">Submit</button>
</form>

And do style your button in css like:

并在css中设置您的按钮样式:

.submitbutton {
  background:url('....') // your custom image
}

Then your custom image will act as the submit button and invoke the form action when click the enter key.

然后,您的自定义图像将充当提交按钮,并在单击回车键时调用表单操作。

#2


0  

It worked for me by adding ng-submit, ng-controller & button type as submit

通过添加ng-submit,ng-controller和按钮类型作为提交,它对我有用

<form ng-submit="func()" ng-controller="MyController"> <button type="submit">Submit</button </form>

#1


10  

Make your button type submit and add a class attribute and style your button to make it an image like:

让您的按钮类型提交并添加一个类属性并设置您的按钮样式,使其成为如下图像:

<form ng-submit="someAction()">
 <button type="submit" class="submitbutton">Submit</button>
</form>

And do style your button in css like:

并在css中设置您的按钮样式:

.submitbutton {
  background:url('....') // your custom image
}

Then your custom image will act as the submit button and invoke the form action when click the enter key.

然后,您的自定义图像将充当提交按钮,并在单击回车键时调用表单操作。

#2


0  

It worked for me by adding ng-submit, ng-controller & button type as submit

通过添加ng-submit,ng-controller和按钮类型作为提交,它对我有用

<form ng-submit="func()" ng-controller="MyController"> <button type="submit">Submit</button </form>