功能:
輸入手機號,實時判斷手機號輸入的是否符合規則:
如果不合規則,則提交按鈕為禁用狀態,手機號信息不可提交,按鈕顯示灰色背景;
如果符合規則,則可提交所輸入的手機號信息,并將按鈕背景設成紅色。
代碼如下:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style> .box{ width: 400px; margin: 50px auto; border: 1px solid #ccc; padding: 50px; } #phone{ text-align: center; margin-bottom: 20px; border: 1px solid #ccc; color: #333; } .submit, .disable, #phone{ display: block; width: 190px; height: 35px; border-radius: 5px; margin-left:auto; margin-right:auto; } .disable{ border: none; background-color: #ccc; color: #fff; } .submit{ border: none; background-color: red; color: #fff; } </style></head><body> <div class="box"> <input id="phone" type="text" placeholder="輸入領券手機號" maxlength="11"> <button id="submit" class="disable" disabled>確認領取</button> </div> <script src="jquery.min.js"></script> <script> $(function () { var $phone = $('#phone'); var $submit = $('#submit'); $phone.on('input 效果:
用戶輸入的手機號不合規則時:

用戶輸入的手機號符合規則時:

新聞熱點
疑難解答