gpt4 book ai didi

angularjs - 按 'Enter' 执行取消按钮而不是提交

转载 作者:行者123 更新时间:2023-12-04 23:01:08 25 4
gpt4 key购买 nike

<form class="stdform stdform2" name="projectForm" ng-submit="saveProject(project, projectForm)"
novalidate="novalidate">
<p>
<div class="par control-group" ng-class="{'has-error': projectForm.projectName.$invalid && (projectForm.projectName.$dirty || submitted)}">
<label class="control-label" for="projectname">Name</label>

<div class="controls">
<span class="field">
<input id="projectname" type="text" ng-model="project.name" name="projectName" class="form-control"
required/>
<label ng-show="projectForm.projectName.$error.required && (projectForm.projectName.$dirty || submitted)"
class="error" for="projectname">Please type project name</label>
</span>
</div>
</div>
</p>
<p>
<label>Description</label>
<span class="field">
<textarea ng-model="project.description" name="projectDescription"
style="resize: vertical; height: 110px;" class="form-control input-default"></textarea>
</span>
</p>

<p class="stdformbutton">
<button class="btn btn-default" ui-sref="app.project.list">Cancel</button>
<button class="btn btn-primary" type="submit">{{saveMessage}}</button>
</p>
</form>

为什么在按下键盘上的“Enter”键后我重定向到 app.project.list而不是拥有 saveProject(project, projectForm)函数执行了吗?

最佳答案

默认 type for buttons is submit .您必须明确将其取消设置为 "button"避免提交操作:

<p class="stdformbutton">
<button class="btn btn-default" type="button" ui-sref="app.project.list">Cancel</button>
<button class="btn btn-primary" type="submit">{{saveMessage}}</button>
</p>

您也可以设置 type="reset"如果你想让它清除 input值。

关于angularjs - 按 'Enter' 执行取消按钮而不是提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24011853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com