下面是csdn上的一位老兄(不是我)的代码
<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>
<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>
解决方案 »
- 请帮忙解决一下传值时的编码问题。
- 火狐和谷歌浏览器,在js里怎么选中一个单词?
- 新手求助,刚学js
- <td>高度的问题?(急)
- one+a.style.background="#f00"; a参数1 id是one1。这样写不对help!
- 如何将一组特定标签放入一数组中。
- 如何用print方法打印iframe中的内容
- [新手]: 打开一个页面,全屏,无工具条的 代码.急,在线等!!
- 100分求旋转90度接下来的问题?
- jquery设置c:foreach标签的items属性值
- 有一个难度很大的问题,请高手解决。如有一个父窗口,要控制子窗口,但我不知子窗口写有什么javascript代码,我就只想不要这个子窗口中的
- 如何把子窗体的一个数组中的内容赋值给父窗体中的Select对象中
^(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])$
<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>