如:我要输入姓名,必须是20个以内,要是超过20个汉字就在文本框后面提示“20长度以内的汉字”
代码,怎样写的
<div id="form"><input type="text" id="name" name="name" oninput="check();" /> </div>
<script type="text/javascript">
function check(){
var name= document.getElementById("name").value;
if(name.length>20) {
var form = document.getElementById("form");
var newNode = document.createElement("div");
newNode.innerHTML =" 20é¿åº¦ä»¥å çæ±å";
form .appendChild(newNode);
}
</script>追é®
å¦ææè¦æ·»å æ交æé®ï¼å¤ææ¯å¦æ¯20个å符ï¼æ¯å°±æ交ï¼å¦åç»åº" 20é¿åº¦ä»¥å çæ±å";
追ç
function check(){
var name= document.getElementById("name").value;
if(name.length>20) {
var form = document.getElementById("form");
var newNode = document.createElement("div");
newNode.innerHTML =" 20é¿åº¦ä»¥å
çæ±å";
form .appendChild(newNode);
return false;
}
}
æ交ä¸äºåï¼èä¸è¾å ¥å¯¹äºå¤æä¹ä¸å¥½ç¨
追çç»ä½ åå
¨å§..
function check(){
var name= document.getElementById("name").value;
if(name.length>20) {
var form = document.getElementById("form");
var newNode = document.createElement("div");
newNode.innerHTML =" 20é¿åº¦ä»¥å
çæ±å";
form .appendChild(newNode);
return false;
}
}