2015-12-14 70 views
1

我用斜角和引導在html中做了一個簡單的表單。我的問題是,當我按Enter輸入時,它會從ng-click中調用我的提交方法。當我按下輸入問題時提交,HTML表格

<form id="detaliiCursa" class="form-horizontal"> 
    <h3> Detaliile cursei </h3> 

    <div class="form-group"> 
    <label class="col-md-3 control-label">Sursa:</label> 

    <div class="col-md-8"> 
     <input id="sourcePoint" type="text" class="form-control" name="sourcePoint" ng-model="detaliiCursa.sursa"/> 
    </div> 
    </div> 

    <div class="form-group"> 
    <label class="col-md-3 control-label">Destinatie:</label> 

    <div class="col-md-8"> 
     <input id="destinationPoint" type="text" class="form-control" name="destinationPoint" ng-model="detaliiCursa.destinatie"/> 
    </div> 
    </div> 

    <div class="form-group"> 
    <div class="col-xs-9 col-xs-offset-3"> 
     <button type="submit" class="btn btn-primary" name="submit" value="submit" ng-click="submit()">Submit</button> 
    </div> 
    </div> 
</form> 

你知道我只有在按Submit按鈕時才能調用「submit()」嗎?

謝謝。

+3

http://stackoverflow.com/questions/19549985/prevent-form-submission-on-enter-key – mindparse

回答

4

您可以將您的按鈕類型從submit更改爲button。雖然輸入類型爲submit它嘗試提交表單,然後單擊表單的任何輸入元素。

HTML

<div class="form-group"> 
    <div class="col-xs-9 col-xs-offset-3"> 
    <button type="button" class="btn btn-primary" name="submit" value="submit" ng-click="submit()">Submit</button> 
    </div> 
</div> 

Working Plunkr

相關問題