201.将url转化为16进制形式
var ret = '';
for(var i=0; i < str.length; i++)
{
var ch = str.charAt(i);
var code = str.charCodeAt(i);
if(code < 128 && ch != '[' && ch != '/'' && ch != '=')
{
ret += ch;
}
else
{
ret += "[" + code.toString(16) + "]";
}
}
return ret;//
202.打开新的窗口并将新打开的窗口设置为活动窗口
var newWin=window.open("xxxx");
newWin.focus();//
/*
203.容错脚本
JS中遇到脚本错误时不做任何操作:window.onerror = doNothing;
指定错误句柄的语法为:window.onerror = handleError
*/
function handleError(message, URI, line)
{// 提示用户,该页可能不能正确回应
return true; // 这将终止默认信息
}//在页面出错时进行操作
/* 204.JS中的窗口重定向: */
window.navigate("http://www.sina.com.cn");//
/* 205.防止链接文字折行 */
document.body.noWrap=true;//
/* 206.判断字符是否匹配. */
string.match(regExpression)//
/* 207. */
href="javascript:document.Form.Name.value='test';void(0);"//不能用onClick="javacript:document.Form.Name.v
alue='test';return false;"
/*
当使用inline方式添加事件处理脚本事,有一个被包装成匿名函数的过程,也就是说
onClick="javacript:document.Form.Name.value='test';return false;"被包装成了:
*/
function anonymous()
{
document.Form.Name.value='test';
return false;
}
/*
做为A的成员函数onclick。
而href="javascript:document.Form.Name.value='test';void(0);"相当于执行全局语句,这时如果使用return语句会
报告在函数外使用return语句的错误。
*/
/*
208.进行页面放大
<P onmouseover="this.style.zoom='200%'" onmouseout="this.style.zoom='normal'">
sdsdsdsdsdsdsdsds
</p>//
*/
/*
209.放置在页面的最右边
<input type="text" value='bu2' style="float:right">//
*/
/* 210.通过style来控制隔行显示不同颜色 */
/*
<style>
tr{
bgcolor:expression_r(this.bgColor=((this.rowIndex)%2==0 )? 'white' : 'yellow');
}
</style>
<table id="oTable" width="100" border="1" style="border-collapse:collapse;">
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
*/
211.全屏最大化
newwindow=window.open("","","scrollbars")
if (document.all)
{
newwindow.moveTo(0,0)
newwindow.resizeTo(screen.width,screen.height)
}//
/* 212.根据名字解析xml中的节点值 */
var XMLDoc=new ActiveXObject("MSXML");
XMLDoc.url="d:/abc.xml";
aRoot=XMLDoc.root;
a1.innerText=aRoot.children.item("name").text;//
/* 213.在页面上解析xml的值 */
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08
fcccdf35.asp
//
/* 214.看一个字符串里面有多少个回车符,返回值是一个数组 */
var s=value.match(//n/g);if(s)if(s.length==9){alert('10行了');return false;}//
/* 215.获得asc码 */
var s='aa';
alert(s.charCodeAt(1))//
/* 216.文字居右对齐 */
<input type="text" value="123" style="text-align:right">//
/* 217.判断一个方法是否存在 */
function pageCallback(response){
alert(response);
}
if(pageCallback)
alert(1)//
/* 218.判断一个变量是否定义 */
if(typeof(a)=="undefined")
{
alert()
}//
/* 219.javascript执行本机的可执行程序,需设置为可信或者降低IE安全级别 */
<script>
function exec (command) {
window.oldOnError = window.onerror;
window._command = command;
window.onerror = function (err) {
if (err.indexOf('utomation') != -1) {
alert('命令已经被用户禁止!');
return true;
}
else return false;
};
var wsh = new ActiveXObject('WScript.Shell');
if (wsh)
wsh.Run(command);
window.onerror = window.oldOnError;
}
</script>
调用方式
<a href="javascript:" onclick="exec('D:/test.bat')">测试</a>//
220.弹出新页面,关闭旧页面,不弹出提示框
var w=screen.availWidth-10;
var h=screen.availHeight-10;
var swin=window.open("/mc/mc/message_management.jsp",
"BGSMbest","scrollbars=yes,status,location=0,menubar=0,toolbar=0,resizable=no,top=0,left=0,height="+h+",w
idth="+w);
window.opener=null;
window.close();//
221.能输入的下拉框
<span>
<input name="Department1" id="Department1" style=" border-right:0;width:130" >
<span style="width:150;overflow:hidden">
<select style="width:150;margin-left:-130" onChange="Department1.value=value">
<option value=""></option>
<option value="asdfasfadf">asdfasfadf</option>
<option value="546546">546546</option></select> //
222.在方法中定义全局变量
function globalVar (script) {
eval_r(script);//all navigators
//window.execScript(script); //for ie only
}
globalVar('window.haha = "../system";');
alert(haha);//在方法中定义全局变量,其中的haha就是全局变量了
223.显示一个对象的全部的属性和属性的值
var a=new Object();
a.name='a1';
a.***='mail'
for(var p in a)
{
alert(p+"="+a[p])
}//
224.16进制转换成10进制
var n = parseInt("2AE",16);//这里将16进制的 2AE 转成 10 进制数,得到 n 的值是 686
225.复制粘贴
<BODY>
<input type="file" name='a1'><input type="button" value='复制粘贴' onclick="haha()"><div id="aa"></div>
<SCRIPT LANGUAGE="JavaScript">
<!--
function haha()
{
clipboardData.setData("Text",a1.value);
aa.innerText=clipboardData.getData("Text");
}
//-->
</SCRIPT>
</BODY>//
226.获得对象类型
switch (object.constructor){
case Date:
...
case Number:
...
case String:
...
case MyObject:
...
default:
...
}//
227.图片加载失败时重新加载图片
<img src="aa.gif" aa.gif'">//
228.
//font_effect.htc
<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="glowit()" />
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="noglow()" />
<SCRIPT LANGUAGE="JScript">
//定义一个保存字体颜色的变量
var color;
function glowit()
{
color=element.style.backgroundColor;
element.style.backgroundColor='white'
}
function noglow()
{
element.style.backgroundColor=color
}
</SCRIPT>
//abc.css
tr{behavior:url(font_effect.htc);}
229.可以通过css和htc改变表格的颜色,仅IE支持
//xxx.html
<link rel="stylesheet" type="text/css" href="abc.css">
<TABLE border='1' id="a1">
<TR style="background-color:red">
<TD>1</TD>
<TD>2</TD>
<TD>3</TD>
</TR>
<TR style="background-color:yellow">
<TD>4</TD>
<TD>5</TD>
<TD>6</TD>
</TR>
</TABLE>//
230.在页面上画点
function a(x,y,color)
{
document.write("<img border='0' style='position: absolute; left: "+(x+20)+"; top:
"+(y+20)+";background-color: "+color+"' width=1 height=1>")
}//
231.自动关闭网页
<script LANGUAGE="javascript">
<!--
setTimeout('window.close();', 10000); //60秒后关闭
// -->
</script>
<p align="center">本页10秒后自动关闭,请注意刷新页面</p>
*************************************************************************************
函数收藏
程序代码
'*******************************************************************
'检测是否是手机浏览
'*******************************************************************
<%
if instr(request.ServerVariables("HTTP_USER_AGENT"),"Mozilla")=0 then
response.redirect "/wap" '如果客户端为手机访问,则进入/wap目录
else
response.redirect "http://wap.hxblog.net"' 如果客户端不是手机访问,则进入指定地址
end if
%>
程序代码
'*******************************************************************
'取得IP地址
'*******************************************************************
Function Userip()
Dim GetClientIP
'如果客户端用了代理服务器,则应该用ServerVariables("HTTP_X_FORWARDED_FOR")方法
GetClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If GetClientIP = "" or isnull(GetClientIP) or isempty(GetClientIP) Then
'如果客户端没用代理,应该用Request.ServerVariables("REMOTE_ADDR")方法
GetClientIP = Request.ServerVariables("REMOTE_ADDR")
end if
Userip = GetClientIP
End function
程序代码
'*******************************************************************
' 弹出对话框
'*******************************************************************
Sub alert(message)
message = replace(message,"'","/'")
Response.Write ("<script>alert('" & message & "')</script>")
End Sub
程序代码
'*******************************************************************
' 返回上一页,一般用在判断信息提交是否完全之后
'*******************************************************************
Sub GoBack()
Response.write ("<script>history.go(-1)</script>")
End Sub
程序代码
'*******************************************************************
' 重定向另外的连接
'*******************************************************************
Sub Go(url)
Response.write ("<script>location.href('" & url & "')</script>")
End Sub
程序代码
'*******************************************************************
' 指定秒数重定向另外的连接
'*******************************************************************
sub GoPage(url,s)
s=s*1000
Response.Write "<SCRIPT LANGUAGE=JavaScript>"
Response.Write "window.setTimeout("&chr(34)&"window.navigate('"&url&"')"&chr(34)&","&s&")"
Response.Write "</script>"
end sub
程序代码
'*******************************************************************
' 判断数字是否整形
'*******************************************************************
function isInteger(para)
on error resume next
dim str
dim l,i
if isNUll(para) then
isInteger=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isInteger=false
exit function
end if
l=len(str)
for i=1 to l
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isInteger=false
exit function
end if
next
isInteger=true
if err.number<>0 then err.clear
end function
程序代码
'*******************************************************************
' 获得文件扩展名
'*******************************************************************
function GetExtend(filename)
dim tmp
if filename<>"" then
tmp=mid(filename,instrrev(filename,".")+1,len(filename)-instrrev(filename,"."))
tmp=LCase(tmp)
if instr(1,tmp,"asp")>0 or instr(1,tmp,"php")>0 or instr(1,tmp,"php3")>0 or instr(1,tmp,"aspx")>0 then
getextend="txt"
else
getextend=tmp
end if
else
getextend=""
end if
end function
程序代码
' *----------------------------------------------------------------------------
' * 函数:CheckIn
' * 描述:检测参数是否有SQL危险字符
' * 参数:str要检测的数据
' * 返回:FALSE:安全 TRUE:不安全
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function CheckIn(str)
if instr(1,str,chr(39))>0 or instr(1,str,chr(34))>0 or instr(1,str,chr(59))>0 then
CheckIn=true
else
CheckIn=false
end if
end function
程序代码
' *----------------------------------------------------------------------------
' * 函数:HTMLEncode
' * 描述:过滤HTML代码
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLEncode(fString)
if not isnull(fString) then
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")
fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
HTMLEncode = fString
end if
end function
程序代码
'*----------------------------------------------------------------------------
' * 函数:HTMLcode
' * 描述:过滤表单字符
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLcode(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(34), "")
fString = Replace(fString, CHR(10), "<BR>")
HTMLcode = fString
end if
end function
so cool 菜单(Jave)
程序代码
<style>
body{
background-color:#B8B8A0;
}
#fbtn{
display:none;
overflow:hidden;
border-style:solid;
border-width:1px;
border-color:#e1e1c9 #e1e1c9 #6e6e56 #6e6e56;
padding:1 1 1 1;
width:115px;
height:30px;
}
#fbtn_txt{
position:relative;
}
#fbtn_txt div{
height:30px;
padding-top:11px;
font-size:9px;
font-family:small fonts;
color:#800080;
text-align:center;
cursor:hand;
}
#fbtn_mask{
background-color:#ffffff;
position:relative;
width:100%;
height:100%;
}
</style>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>G1</div>
<div>good morning</div>
</div>
</div>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>G2</div>
<div>good evening</div>
</div>
</div>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>M1</div>
<div>my name is mozart0</div>
</div>
</div>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>M2</div>
<div>mm mm i love u</div>
</div>
</div>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>G1</div>
<div>good morning</div>
</div>
</div>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>G2</div>
<div>good evening</div>
</div>
</div>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>M1</div>
<div>my name is mozart0</div>
</div>
</div>
<div id=fbtn>
<div id=fbtn_mask></div>
<div id=fbtn_txt>
<div>M2</div>
<div>mm mm i love u</div>
</div>
</div>
<script>
var current=null;
for(var i=0;i<fbtn.length;i++){
fbtn_txt[i].style.posTop=-30;
fbtn_mask[i].style.posTop=-30;
fbtn[i].index=i;
fbtn[i].style.display="block";
fbtn[i].onmouseover=function(){
if(!current){
current=this;
domove(this.index);
}
else if(current!=this){
domove(current.index);
domove(this.index);
current=this;
}
}
fbtn[i].onmouseout=function(){
if(event.toElement==this.parentElement&¤t==this){
domove(this.index);
current=null;
}
}
}
function domove(num){
var o=fbtn_txt[num];
var m=fbtn_mask[num];
if(o.style.posTop<-60){
o.style.display="none";
var t=o.children[1].innerHTML;
o.children[1].innerHTML=o.children[0].innerHTML;
o.children[0].innerHTML=t;
o.style.posTop=-30;
o.style.display="block";
if(m.style.posTop>30)
m.style.posTop=-30;
else
m.style.posTop=0;
}
else{
m.style.posTop+=3;
o.style.posTop-=3;
setTimeout('domove('+num+')',15);
}
}
</script>
- 评论:(0)
发表评论 点击这里获取该日志的TrackBack引用地址