2017-08-04 80 views

回答

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>