html - form 表單 用戶名提示和錯誤提示分開顯示?
問題描述
點擊輸入框,顯示用戶名提示,點擊立即注冊按鈕,在輸入框下顯示錯誤提示
<form name='checkForm' ng-init='isEmpty=false;'> <p class='form-group'><label class='col-sm-3 control-label'>用 戶 名</label><p class='col-sm-8 account'> <input type='text' placeholder='您的賬戶名和登錄名'ng-model='account'name='account'required='required'ng-pattern='regularList.account'ng-blur='checkForm.account.$blured = false;'ng-focus='checkForm.account.$blured = true;'autocomplete='off'/> <span ng-class='{’right’:(checkForm.account.$error.pattern),’error’:checkForm.account.$valid}'></span></p><span ng-messages='isEmpty && checkForm.account.$blured && checkForm.account.$error' role='alert'> <span ng-message='required' style='color: #ff0000'>用戶名不能為空</span></span><span ng-messages='checkForm.account.$blured && checkForm.account.$error' role='alert'> <span ng-message='pattern'style='color: #ff0000'>用戶名為4-20位中文數字與英文字母組成!</span></span> </p> <p ng-if='checkForm.account.$blured==true'><p ng-show='checkForm.account.$blured'> <i></i> <span>!支持中文、字母、數字、“-”“_”的組合,4-20個字符</span></p> </p>
具體效果如下
現在是輸入內容不希望顯示錯誤提示我現在的問題是,輸入相應的內容,會有錯誤的提示,效果見下
目的:輸入內容不提示錯誤,點擊立即注冊,如果不符合相應的規范,再提示錯誤。求指點,謝謝
問題解答
回答1:也是醉了。。。<input type='text' placeholder='您的賬戶名和登錄名'
ng-model='account' ng-pattern='regularList.account'/>
<span ng-show='showAccountError' role='alert'>
<span style='color: #ff0000'>用戶名為4-20位中文數字與英文字母組成!</span>
</span>當用戶提交的時候,在controller中用正則判斷$scope.account是否合法,不合法的話,就讓$scope.showAccountError=true.在頁面初始化的時候給這個變量賦false。
相關文章:
1. mac連接阿里云docker集群,已經卡了2天了,求問?2. javascript - js 有什么優雅的辦法實現在同時打開的兩個標簽頁間相互通信?3. java - spring-data Jpa 不需要執行save 語句,Set字段就可以自動執行保存的方法?求解4. css3 - 在sublime text里, 如何讓emmet生成的帶前綴css屬性垂直對齊?5. css3 - Typecho 后臺部分表單按鈕在 Chrome 下出現靈異動畫問題,求解決6. html5和Flash對抗是什么情況?7. javascript - 一個抽獎的效果(如圖)?8. javascript - weex和node,js到底是怎樣一個關系呢?9. javascript - 求解答,koa-bodyparser獲取到的參數是空對象,為什么?????10. 想找個php大神仿個網站。
