那个不知道来对没?
问一下如何设置input框必含内容?
意思就是,input框必须含有我设定的内容。。
如,我设定必含内容要有1 ,那么只输入2,不含有1的话就不行。。
谢谢了。
------解决方案--------------------
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function check()
{
var v = document.getElementById( "t ").value;
if(v.indexOf( "1 ")==-1)
{
alert( "include 1 ");
return false;
}
else
{
alert( "ok ");
}
}
</script>
</HEAD>
<BODY>
<INPUT TYPE= "text " id= "t ">
<INPUT TYPE= "button " onclick= "check(); " value= "click ">
</BODY>
</HTML>
------解决方案--------------------
<html>
<script language= "javascript ">
function check() {
var key = window.event.keyCode;
if(key != 97) {
window.event.keyCode = 0;
}
}
</script>
<body>
<form name= "test ">
<input type= "text " name= "c " onkeypress= "check() ">
</form>
</body>
</html>
if(key != 97)这里面条件随便你改
------解决方案--------------------
可能正则表达式好一点。
------解决方案--------------------
<html>
<script language= "javascript ">
function check() {
var key = window.event.keyCode;
if(key == 1 || key==2 || key==3||key==4) {
}else
{
window.event.keyCode=0;
}
}
</script>
<body>
<form name= "test ">
<input type= "text " name= "c " onkeypress= "check() ">
</form>
</body>
</html>
------解决方案--------------------
使用正则表达式