JS代码判断集锦(之二)
<INPUT TYPE="button" value="登录" tabindex="4">
<INPUT TYPE="button" value="注册" tabindex="4">
function trim(inputstr) //去处空格,在获取客户端录入的表单信息前,
都先trim一下再提交 例如:“form1.org_name.value = trim(form1.org_name.value);”
{
if(!inputstr.length>0) return "";
var starts=0;
var ends=inputstr.length;
while(starts<ends)
{
if(inputstr.substring(starts,starts+1)==" ")
starts++;
else
break;
}
while(starts<ends)
{
if(inputstr.substring(ends-1,ends)==" ")
ends--;
else
break;
}
return inputstr.substring(starts,ends);
}
function isvalidcode(inputs) //校验邮政编码
{
var i,temp;
var isvalidcode = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0||inputstr.length!=6) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9"))
{
isvalidcode=false;
break;
}
}
return isvalidcode;
}
function isvalidtel(inputs) //校验电话号码
{
var i,temp;
var isvalidtel = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9" || temp=="-"))
{
isvalidtel=false;
break;
}
}
return isvalidtel;
}
function isrealnum(inputs) //校验实数(含小数点)
{
var i,temp;
var isrealnum = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9" || temp=="."))
{
isrealnum=false;
break;
}
}
return isrealnum;
}
function isnumeric(inputs) //校验是否整数
{
var i,temp;
var isnumeric = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
//isvalid = true;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9"))
{
isnumeric=false;
break;
}
}
return isnumeric;
}
function isvalidide(inputs) //校验身份证
{
var i,temp;
var isvalidide = true;
inputstr=trim(inputs);
if(inputstr.length == null || inputstr.length == 0 || (inputstr.length != 15 && inputstr.length != 18)) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp>="0" && temp<="9") || temp == "x" || temp == "X"))
{
isvalidide=false;
break;
}
}
return isvalidide;
}
function isvalidname(inputs) //校验账号2~15位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidname = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length > 15 || inputstr.length < 2) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidname=false;
break;
}
}
return isvalidname;
}
function isvalidphoto(inputs) //校验照片扩展名
{
var i,temp;
var isvalidphoto = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0) return true; //没有相片也允许的
temp=inputstr.substring(inputstr.lastIndexOf(".")+1);
temp = temp.toLowerCase();
if(!(temp == "bmp" || temp == "jpg" || temp == "gif"))
{
isvalidphoto=false;
}
return isvalidphoto;
}
function isvalidzgh(inputs) //校验职工号8位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidzgh = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length != 8) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidzgh=false;
break;
}
}
return isvalidzgh;
}
function isvalidxh(inputs) //校验学号7位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidxh = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length != 7) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidxh=false;
break;
}
}
return isvalidxh;
}
function isvalidkcid(inputs) //校验课程编号5位(即只能是数字组成的串)
{
var i,temp;
var isvalidkcid = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0||inputstr.length!=5) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9"))
{
isvalidkcid=false;
break;
}
}
return isvalidkcid;
}
function isvalidnamee(inputs) //校验账号4~20位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidname = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length > 20 || inputstr.length < 4) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidname=false;
break;
}
}
return isvalidname;
}
<Script language="JavaScript">
function login()
{
form1.UNAME.value = trim(form1.UNAME.value);
form1.PWD.value = trim(form1.PWD.value);
form1.PWD2.value = trim(form1.PWD2.value);
form1.EMAIL.value = trim(form1.EMAIL.value);
form1.NC.value = trim(form1.NC.value);
if(!isvalidname(form1.UNAME.value))
{
alert("请您注意:用户名必须为『2~15位英文或数字』!");
form1.UNAME.focus();
return false;
}
else if(!isvalidname(form1.PWD.value))
{
alert("请您注意:密码必须为『2~15位英文或数字』!");
form1.PWD.focus();
return false;
}
else if(!isvalidname(form1.PWD2.value))
{
alert("请您注意:密码确认也必须为『2~15位英文或数字』!");
form1.PWD2.focus();
return false;
}
else if(form1.PWD.value != form1.PWD2.value)
{
alert("两次密码不一致!");
form1.PWD.focus();
return false;
}
else if(form1.EMAIL.value == "" || form1.EMAIL.value.length > 100)
{
alert("请输入邮件!");
form1.EMAIL.focus();
return false;
}
else if(form1.NC.value == "" || form1.NC.value.length > 15)
{
alert("请输入昵称!");
form1.NC.focus();
return false;
}
else if(window.confirm("您确信提交!"))
return true;
else
return false;
}
function regedit()
{
var litop = (screen.height - 162)/2;
var lileft = (screen.width - 360)/2;
window.open("/regedit.aspx", "reg", "titlebar=no,fullscreen=no,dependent=yes,height=162,width=360,
top=" + litop + ",left=" + lileft + ",
toolbar=no,menubar=no,scrollbars=no,resizable=no,
channelmode=no,status=no,location=no,directories=no");
}
</Script>
1. 禁止复制(copy),禁用鼠标右键!
<SCRIPT>
//加入页面保护
function rf()
{return false; }
document.oncontextmenu = rf
function keydown()
{if(event.ctrlKey ==true || event.keyCode ==93 || event.shiftKey ==true){return false;} }
document.onkeydown =keydown
function drag()
{return false;}
document.ondragstart=drag
function stopmouse(e) {
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
return false;
else if
(navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
alert("版权没有,但别复制 :)");
return false;
}
return true;
}
document.onmousedown=stopmouse;
if (document.layers)
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=stopmouse;
</SCRIPT>
<script language="javascript">
function JM_cc(ob){
var obj=MM_findObj(ob); if (obj) {
obj.select();js=obj.createTextRange();js.execCommand("Copy");}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
</script>
2. JS和HTML互转
<body>
<style>
body{font-size:9pt}
textarea {color="#707888";font-family:"verdana"}
.inputs {color="#707888";border:1px solid;background:#f4f4f4}
</style>
在这里输入你需要转换的格式,可以是JavaScript也可以是DHtml.
<br>
<textarea id="codes" style="width:730;height:300">
</textarea>
<br>
<button class="inputs">
清除输出
</button>
<button class="inputs">
全选代码
</button>
<button class="inputs">
拷贝代码
</button>
<button class="inputs">
粘贴代码
</button>
<button class="inputs">
Js转Html
</button>
<button class="inputs">
Html转Js
</button>
<button class="inputs">
点击显示源文件
</button>
<button class="inputs">
预览代码[F12]
</button>
<br>
这个是输出格式的窗口:
<br>
<textarea id="outputs" style="width:730;height:300"></textarea>
<br>
一个不好的消息:这个Js转Html部分现在只是支持由这个程序生成的
<br>
作者:FlashSoft2000 QQ:14433548
<input id="hide" style='display:none'>
<script>
//定义title
document.title="多功能网页转换"
//显示网页源文件
function writes()
{
outputs.value=document.body.outerHTML;
}
//清除输出窗口
function clears()
{
outputs.innerHTML='';
}
//替换特定字符
//n1字符串,n2要替换的字,n3替换的字
function commute(n1,n2,n3)
{
var a1,a2,a3=0,a0=''
a1=n1.length;
a2=n2.length;
for(x=0;x<=(a1-a2);x++)
{
if(n1.substr(x,a2)==n2)
{
a0+=n1.substring(a3,x);
a0+=n3;
x+=(a2-1);
a3=x+1;
}
}
if(a3<a1)a0+=n1.substring(a3,a1)
{
return a0;
}
}
//转换JavaScript为DHtml
function js2html()
{
hide.value=codes.value
hide.value=commute(hide.value,'\\"','"');
hide.value=commute(hide.value,'document.write("','');
hide.value=commute(hide.value,'")','');
hide.value=commute(hide.value,'<script>','');
hide.value=commute(hide.value,'<\/script>','');
outputs.value=hide.value
}
//转换DHtml为JavaScript
function html2js()
{
hide.value=codes.value
hide.value=commute(hide.value,'"','\\"');
hide.value=commute(hide.value,'\\','\\\\');
hide.value=commute(hide.value,'<\/script>','<\\/script>');
outputs.value="<script>document.write(\""+hide.value+"\")<\/script>"
}
//预览代码
function seeHtm()
{
open().document.write("<title>测试代码窗口</title>"+outputs.value);
}
//用快捷键F12预览
document.onkeydown=seeHtms
function seeHtms()
{
if((event.keyCode==123))
{
open().document.write("<title>测试代码窗口</title>"+outputs.value);
}
}
//全选代码
function ta()
{
outputs.select()
}
//拷贝代码
function tc()
{
document.execCommand("Copy")
}
//粘贴代码
function tp()
{
outputs.focus()
document.execCommand("Paste")
}
</script>
广告JS代码效果大全
1.[普通效果]
现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,下面就是实现效果所需代码:
var delta=0.015
var collection;
function floaters() {
this.items = [];
this.addItem =
function(id,x,y,content)
{
document.write('<DIV id='+id+' style="Z-INDEX: 0; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
var newItem = {};
newItem.object = document.getElementById(id);
newItem.x = x;
newItem.y = y;
this.items[this.items.length] = newItem;
}
this.play =
function()
{
collection =
this.items
setInterval('play()',10);
}
}
function play()
{
if(screen.width<=800)
{
for(var i=0;i<collection.length;i++)
{
collection.object.style.display = 'none';
}
return;
}
for(var i=0;i<collection.length;i++)
{
var followObj = collection.object;
var followObj_x = (typeof(collection.x)=='string'?eval(collection.x):collection.x);
var followObj_y = (typeof(collection.y)=='string'?eval(collection.y):collection.y);
if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
followObj.style.left=followObj.offsetLeft+dx;
}
if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
followObj.style.top=followObj.offsetTop+dy;
}
followObj.style.display = '';
}
}
var theFloaters =
new floaters();
theFloaters.addItem('followDiv1','document.body.clientWidth-100',0,'</a><br><a href=广告链接地址 target=_blank><img src=广告图片地址 width=100 height=400 border=0></a>' target=_blank);
theFloaters.addItem('followDiv2',0,0,'<br><a href=广告链接地址 target=_blank><img src=广告图片地址 width=100 height=400 border=0></a>' target=_blank);
theFloaters.play();
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用 调用即可!注意修改广告图片地址和连接地址!