function checkwenben() {
if ( document.form1.wenben.value.length<3000) {
window.alert('form1表單的wenben域輸入不能小於3000字元!版');
document.form1.wenben.focus();
return false;
}
}
然後在提交權的按鈕上加入
onclick="javascript:return checkwenben()"
『貳』 js如何限制<input>中輸入的最大字元數
寫onkeyup事件
js獲取文本框的值個數進行判斷
直接使用maxlength='20'
<input type="text" name="email" maxlength="55" />
『叄』 用JS控制一個輸入框,要求裡面只能輸入字數並且長度必須是11位,以下操作有問題,應該怎麼改正
1、新建一個html文件,命名為test.html。
『肆』 JS 如何限制中文字元輸入字數
1、在html中定義一個input輸入框,給輸入框設置一個id值
2、在輸入框綁定一個onkeydown事件
3、定義onkeydown事件發生時的處理函數controlLen
4、在controlLen函數中檢查input輸入框的輸入值長度n
5、當大於規定的字元長度時,利用字元串的substring重新截取輸入值的前n個值,重新賦值給input框,同時alert提示。
示例:
js代碼:<script type="text/javascript"> function controlLen(){ //獲取input輸入框元素 var inputText = document.getElementById('mytext').value; if(inputText.length > 10){ var text = inputText.substring(0,10); document.getElementById('mytext').value = text;//從新設置input輸入框的值 alert("最多輸入10個字元"); }}</script>html代碼:<body><input type="text" id="mytext" value="" onkeydown="controlLen();"/></body>
『伍』 JS怎麼控制文本框輸入的長度
JS控制文本框輸入的長度的方法如下:
1、html頁面中有以下文本:
<input id="groupidtext" type="text" style="width: 100px;" maxlength="6" /></td>
2、用js限制輸入的最大長度的腳本如下:
$(function)
$('#groupidtext').on{'input', function(e)}
if(this.value.length === 6) { //如果輸入長度等於6,則禁用輸入}
$('input[type="submit"]').prop('disabled', false);
else
$('input[type="submit"]').prop('disabled', true);
js限制文本框輸入的長度為18位字元, 只能是數字和字母,如果輸入的字元超過18位就不能在輸入了。
『陸』 js中怎麼控制一個文本框只能輸入0.0-1.9之間的數據還有0.00-1.99之間。急!
文本框可以綁定keypress事件來判斷按鍵的keycode值,0.0-1.9如下代碼:
input.addEventListener("keypress",function(e){
if((this.value.length==0&&(e.keyCode==48||e.keyCode==49))
||(this.value.length==1&&e.keyCode==46)
||(this.value.length==2&&e.keyCode>=48&&e.keyCode<=57)){
}else{
e.preventDefault();
}
});
//防止輸入法輸入中文,輸入法輸入中文只觸發keydown事件並且keycode都是229
input.addEventListener("keydown",function(e){
if(e.keyCode==229){
e.preventDefault();
}
});
另外需要注意的是文本框要設置maxlength(即允許輸入的最大文本字元數)屬性為3,還要禁用粘貼、拖拽等其他可能的注入文本方式。希望能幫到樓主
『柒』 javascript 限制文本框輸入長度不能超過10個中文字元或20個英文字元 求代碼
直接html標簽就能做到的功能,還要用js..
<input type="text" maxlength="20" />
『捌』 js 限制最少輸入字數
方法一:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>JS限制輸入字數</title>
<scripttype="text/javascript">
functionisNotMax(oinput){
if(oinput.value.length>oinput.getAttribute("maxlength")){
returnoinput.value.substring(0,oinut.getAttribute("maxlength"));
}else{
returnoinput.value;
}
}
</script>
</head>
<body>
<h3>JS限制輸入字數1</h3>
<inputstyle="height:100px;width:600px;border:1pxsolid#333;"maxlength="10"></input>
</body>
</html>
方法二:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>JS限制輸入字數2</title>
</head>
<body>
<inputtype="text"size="70"maxlength="20"name="giftDescribe"onkeyup="javascript:checkWord(20)"onblur="javascript:hiddWordDiv()">
</body>
</html>
『玖』 js 限制文本域:一個訂單系統,手機號碼那裡限制一定要輸入11位數字,請問怎麼設置,感謝
<script>
var p = /^[\d]{11}$/; // 正則 表示 開頭為數字 要11位 結尾
function chk(n) { // 檢測函數
if(!p.test(n.value)) { // 檢測值input的值是否由數字組合並要11位 如果不是則提示
alert('只允許數字並要11位');
n.select(); // 選中輸入框內容
}
}
</script>
<body>
<input type="text" name="name" onblur="chk(this)"/> <!-- 失去焦點時開始檢測 調用chk函數 -->
</body>