有沒有一種可能的方式,有人可以做一個jQuery表單驗證程序,實時提供表單是否對用戶有效。例如,登錄時使用的字符太多(以防止數據庫溢出)。jQuery表單驗證程序
<input type="text" title="Username" id="user" maxlength="25" />
<input type="password" title="Password" id="pass" maxlength="25" />
然後一些jQuery(最大文本值將被設置爲25個字符)。
$("#user").on("keyup", function (event) {
const max_length = 25; // the max length of the #user form element
var inputed_length = $(this).length, new_length = max_length - inputed_length;
var msg = new_length + " characters remaining.";
var node_to_be_appended = $("<td class='in'>" + msg + "</td>");
if ($(".in").length === 0) {
$(this).parent().append(node_to_be_appended);
} else {
$(".in").text(msg);
}
});
歡迎堆棧溢出!目前尚不清楚你的問題是什麼,你能否詳細說明一下? –