在我的項目中,有一個輸入密碼的文本框,密碼字符數限制爲15個。所以,我希望儘快通過javascript顯示警報消息用戶嘗試輸入第16個字符。請幫忙!javascript代碼在15次擊鍵後顯示警告消息
1
A
回答
0
使用jQuery:
$("#inputFieldId").on("input propertychange", function(){
var val = this.value;
if(val.length > 15) {
this.value = val.substring(0,15); //comment if you don't want to remove the 16th character
alert("Maximum 15 characters allowed!");
}
});
0
你需要提及你的代碼中捆綁的東西。無論如何,如果你不知道嘗試這種代碼
<input type="text" onkeypress="myFunction(this)" maxlength="5">
<script>
function myFunction(e) {
var maxlen= e.maxLength;
if(e.value.length >= maxlen)
alert("Max length is limited to" +maxlen);
}
</script>
1
試試這個JavaScript的:
document.getElementById("password").onkeyup = function() {
var text = document.getElementById("password").value
if(text.length> 15){
alert("too much text")
}
};
<input id="password" type="password" placeholder="password">
1
試試這個。
function alrtMsg() {
var x = document.getElementById("pwd").value;
if(x.length > 16){
\t alert("maximum length is 16");
\t document.getElementById("pwd").value = '';
}
}
<html>
<body>
<input type="password" id="pwd" onkeyup="alrtMsg()">
</body>
</html>
相關問題
- 1. 提交後顯示警告消息
- 2. 點擊確定後顯示警告消息和重定向
- 3. 點擊接受後顯示警告消息和重定向
- 4. 顯示一個消息JavaScript警告註銷後
- 5. reactjs在單擊鏈接時顯示警告消息
- 6. 在asp.net中點擊複選框顯示彈出警告消息
- 7. 顯示警告消息:在確定按鈕上單擊RedirectToAction
- 8. C代碼中的QA警告消息
- 9. 警告消息不正確顯示
- 10. 如何在JavaScript警告框中顯示sql錯誤消息?
- 11. JavaScript警告消息不顯示在mvc3中
- 12. Rails 3:單擊鏈接時如何顯示警告消息?
- 13. 顯示警告信息重定向後
- 14. Tkinter警告消息中的「不再顯示消息」複選框
- 15. 警告消息
- 16. 提交後將顯示警報消息
- 17. 如何多次警告消息一次,並且不 - 的JavaScript
- 18. 在eclipse(juno)中顯示javascript代碼的java警告(?)
- 19. 如何在按鈕點擊後顯示「No More Data」消息javascript
- 20. Javascript警告框未顯示
- 21. ADBannerView警告消息
- 22. Javascript - 在警告消息後停止處理
- 23. 回覆後顯示警告
- 24. 我試圖用Javascript單擊瀏覽器後退按鈕時顯示警告消息
- 25. JavaScript警告消息包含URL
- 26. 每15秒運行一次JavaScript代碼
- 27. 在瀏覽器後退按鈕上顯示警告消息,但不顯示刷新時的警報
- 28. 當用戶點擊顯示代碼時添加警告標籤或任何類型的消息
- 29. 找不到項目導入警告消息在Eclipse中顯示
- 30. WAMP:如何在瀏覽器中顯示警告消息?