<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>IP-like Input</title>
<style>
<!--
div.IPDiv { background: #FFFFFF; width: 120; margin:0; font-family: Arial,Tahoma; font-size: 10pt; text-align: center; border-top: 2 ridge threedshadow; border-left: 2 ridge threedshadow; border-right: 2 inset threedhighlight; border-bottom: 2 inset threedhighlight }
input.IPInput { width: 24; margin:0; font-family: Arial,Tahoma; font-size: 10pt; text-align: center; border-width: 0 }
-->
</style>
</head>
<body bgcolor=threedface>
像IP地址输入栏一样的文本框
<script>
IPlikeInputStr = "";
IPlikeInputStr += '<div class="IPDiv">';
for (i=0;i<4;i++) {
IPlikeInputStr += '<input class="IPInput" name="IPInput'+i+'" type="text" size="3" maxlength="3" onkeypress="keyHandle()" onkeyup="checkInput()">'+((i==3) ? '' : '.');
}
IPlikeInputStr += '</div>';
document.write(IPlikeInputStr);
function keyHandle() {
if (event.keyCode<48||event.keyCode>57) {
event.returnValue = false;
}
}
function checkInput() {
if (event.srcElement.name=="IPInput0") {
if (event.srcElement.value==0&&event.srcElement.value.length==3) {
event.srcElement.value="1";
alert("请输入一个界于1和223之间的数值");
event.srcElement.select();
}
if (event.srcElement.value>223) {
event.srcElement.value="223";
alert("请输入一个界于1和223之间的数值");
event.srcElement.select();
}
}
else {
if (event.srcElement.value>255) {
event.srcElement.value="255";
alert("请输入一个界于0和255之间的数值")
event.srcElement.select();
}
}
}
</script>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>IP-like Input</title>
<style>
<!--
div.IPDiv { background: #FFFFFF; width: 120; margin:0; font-family: Arial,Tahoma; font-size: 10pt; text-align: center; border-top: 2 ridge threedshadow; border-left: 2 ridge threedshadow; border-right: 2 inset threedhighlight; border-bottom: 2 inset threedhighlight }
input.IPInput { width: 24; margin:0; font-family: Arial,Tahoma; font-size: 10pt; text-align: center; border-width: 0 }
-->
</style>
</head>
<body bgcolor=threedface>
像IP地址输入栏一样的文本框
<script>
IPlikeInputStr = "";
IPlikeInputStr += '<div class="IPDiv">';
for (i=0;i<4;i++) {
IPlikeInputStr += '<input class="IPInput" name="IPInput'+i+'" type="text" size="3" maxlength="3" onkeypress="keyHandle()" onkeyup="checkInput()">'+((i==3) ? '' : '.');
}
IPlikeInputStr += '</div>';
document.write(IPlikeInputStr);
function keyHandle() {
if (event.keyCode<48||event.keyCode>57) {
event.returnValue = false;
}
}
function checkInput() {
if (event.srcElement.name=="IPInput0") {
if (event.srcElement.value==0&&event.srcElement.value.length==3) {
event.srcElement.value="1";
alert("请输入一个界于1和223之间的数值");
event.srcElement.select();
}
if (event.srcElement.value>223) {
event.srcElement.value="223";
alert("请输入一个界于1和223之间的数值");
event.srcElement.select();
}
}
else {
if (event.srcElement.value>255) {
event.srcElement.value="255";
alert("请输入一个界于0和255之间的数值")
event.srcElement.select();
}
}
}
</script>
</body>
</html>
解决方案 »
- JSP中验证码的问题,求各位大虾帮手下。!
- 如何把字符串解析或者转换层 js 对象
- fullcalendar 求助。。。有没有json ajax调用的源码啊。。。
- 老猫的理想制作w3school javascript 电子书 chm版
- 如何用JS或者后台实现在指定日期系统自动发送邮件???
- 100分 求一正则(2,3,5) 在线等
- 简单的问题 就是不知什么地方不对
- 求验证文本框输入是否为域名的"js"
- 截取字符串函数是什么呀?????
- 怎样用replace一次替换多个字符??
- 我在页面传递参数时,中文变成乱码?为什么??
- 各位大哥有个问题想请教,怎么样实现单选按钮选中,那么下拉框可用,没有选,则下拉框不可用!谢谢
<body>
<input id='po' type=text >
<input type=button value='validate' onclick='aa(po.value)'>
<script>
function aa(strValue)
{
if(strValue.search(/[0-255].[0-255].[0-255].[0-255]/) == 0)
alert('ok')
else
alert('error');
}
</script>
</body>
</html>