- 爱易网页
-
JavaSript
- 怎么加入限制,只能输入文字或数字,请大家帮下忙~
日期:2014-05-16 浏览次数:20536 次
如何加入限制,只能输入文字或数字,请大家帮下忙~~
有如下代码,怎么才能在选中第一个radio后,text中只能输入文字。
选中第二个radio后,text中只能输入数字?
<html>
<head>
<title> </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
</head>
<body>
<center>
<script type= "text/javascript ">
function Search(Tbl,TextValue)
{
var count=0;
var keyWord=TextValue.value;
if(keyWord!= " ")
{
for(var i=0;i <Tbl.rows.length;i++)
{
var tr=Tbl.rows[i];
if(tr.innerHTML.indexOf(keyWord)==-1)
tr.style.display= "none ";
else
{
tr.style.display= "block ";
count++;
}
}
}
if(count==0)
{
alert( '找不到你要的记录! ');
ListAll(Tbl);
}
}
function ListAll(Tbl)
{
for(var i=0;i <Tbl.rows.length;i++)
{
Tbl.rows[i].style.display= "block ";
}
}
</script>
<input name= "ttt " type= "text " style= "width:200 " >
<input type= "button " value= "查找 " onclick= "Search(Tbl1,ttt) " >
<input type= "button " value= "返回 " onclick= "ListAll(Tbl1) ">
<input type= "radio " name= "paytype " value= " " > 文字
<input type= "radio " name= "paytype " value= " " > 数字
<br>
<table width= "500 " id= "Tbl1 " border= "1 ">
<tr> <td> aaa </td> <td> 12 </td> <td> 1988 </td> </tr>
<tr> <td> 呵呵 </td> <td> 56 </td> <td> 1911 </td> </tr>
<tr> <td> 12 </td> <td> 55 </td> <td> 1920 </td> </tr>
<tr> <td> ddd </td> <td> 12 </td> <td> 13 </td> </tr>
<tr> <td> 呵呵 </td> <td> 55 </td> <td> 1877 </td> </tr>
<tr> <td> ddeed </td> <td> 11 </td> <td> 12 </td> </tr>
<tr> <td> ddafd </td> <td> 58 </td> <td> 1988 </td> </tr>
</table>
</center>
</body>
</html>