ENTER键无法正常工作

时间:2013-11-29 07:43:47

标签: javascript jquery html5 angularjs

当我按下回车键时,其通话功能会自动刷新页面。我为取消按钮写的功能

<form name="myForm">
    <div >
        <input type="text" placeholder="First Name" required ng-model="name" />
    </div>
    <div >
        <input type="text" placeholder="Last Name" required ng-model="lname" />
    </div>

    <div >
        <button type="Cancel"  ng-click=clearDetails()>Clear</button>
        <button type="submit"  ng-click=addDetails() ng-disabled="myForm.$invalid">Submit</button>                  
    </div>
</form>

填写任何文本字段后,按下调用clearDetails函数

$scope.addDetails = function() {
var postObj = new Object();
// add details stuff here   
}

$scope.clearDetails = function() {
    //refresh the page stuff here
    //here i am redirecting to the same page
}

3 个答案:

答案 0 :(得分:0)

在许多浏览器上输入考虑作为提交表单或与第一个按钮点击关联..只是一个建议移动提交按钮和取消按钮在HTML中它可能解决问题。

答案 1 :(得分:0)

确保提交按钮的两个属性之间必须有空格。您将代码编写为

<button **type="submit"ng-click=addDetails()** ng-disabled="myForm.$invalid">Submit</button>

一定是

<button **type="submit" ng-click=addDetails()** ng-disabled="myForm.$invalid">Submit</button>

答案 2 :(得分:0)

更改取消按钮的类型以重置:

<form name="myForm">
    <div>
        <input type="text" placeholder="First Name" required ng-model="name" />
    </div>
    <div>
        <input type="text" placeholder="Last Name" required ng-model="lname" />
    </div>
    <button type="reset" ng-click=clearDetails()>Clear</button>
    <button type="submit" ng-click=addDetails() ng-disabled="myForm.$invalid">Submit</button>
</form>