只准输入数字和:(冒号) JS 我要用JavaScript实现文本框只能输入数字 和 :(冒号)最好有详细的代码,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><body> <input onkeyup='checkme(this)' type="text" /> <script> function checkme(el){ el.value=el.value.replace(/[^0-9:]/g,''); } </script></body></html> <html><head><title></title><script type="text/javascript">function show(obj){ var reg=/^[\d|:]*$/g var patt1 = new RegExp(reg); alert(patt1.test(obj));}</script></head><body><input type="text" onblur="show(this.value)"></body></html> 完整代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><form action="http://www.baidu.com" id="myForm">输入:<input type="text" id="txtName" /><br><input type="button" id="sub" value="提交" onclick="sb()" /></form></body></html><script language="javascript">function sb(){ var pattern=/^(\d|:)+$/; var name=document.getElementById('txtName').value; if(!pattern.test(name)){ alert("输入不合法"); document.getElementById('txtName').focus(); document.getElementById('txtName').select(); }else { document.getElementById('myForm').submit(); }}</script> window.showModalDialog打开子窗口,为什么子窗口的iframe变成了只读? 大家帮我看看这个脚本 js求助 看看这个javascript为什么不能实现页面跳转 css中怎么设置表中的一个TD的宽度自动适应内容的宽度? 根据子div的ID获取父div 急急急急~~~~ js中如何判断一个table中存在不存在行 给servlet传参数 谁做过比较酷的2d弹出窗口?高分 <body onload=javascript:window.open> JS与TXT文本的问题。。请高手进,在线等+++++++++++ js处理html中的双引号
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<body>
<input onkeyup='checkme(this)' type="text" />
<script>
function checkme(el){
el.value=el.value.replace(/[^0-9:]/g,'');
}
</script>
</body>
</html>
<script type="text/javascript">
function show(obj)
{
var reg=/^[\d|:]*$/g
var patt1 = new RegExp(reg); alert(patt1.test(obj));
}
</script>
</head><body>
<input type="text" onblur="show(this.value)">
</body></html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="http://www.baidu.com" id="myForm">
输入:<input type="text" id="txtName" /><br>
<input type="button" id="sub" value="提交" onclick="sb()" />
</form>
</body>
</html>
<script language="javascript">
function sb()
{
var pattern=/^(\d|:)+$/;
var name=document.getElementById('txtName').value;
if(!pattern.test(name)){
alert("输入不合法");
document.getElementById('txtName').focus();
document.getElementById('txtName').select();
}else
{
document.getElementById('myForm').submit();
}
}
</script>