JavaScript使用技巧精.docx

上传人:b****8 文档编号:30660086 上传时间:2023-08-19 格式:DOCX 页数:23 大小:26.69KB
下载 相关 举报
JavaScript使用技巧精.docx_第1页
第1页 / 共23页
JavaScript使用技巧精.docx_第2页
第2页 / 共23页
JavaScript使用技巧精.docx_第3页
第3页 / 共23页
JavaScript使用技巧精.docx_第4页
第4页 / 共23页
JavaScript使用技巧精.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

JavaScript使用技巧精.docx

《JavaScript使用技巧精.docx》由会员分享,可在线阅读,更多相关《JavaScript使用技巧精.docx(23页珍藏版)》请在冰豆网上搜索。

JavaScript使用技巧精.docx

JavaScript使用技巧精

JavaScript使用技巧精

(一).确认删除用法:

1.BtnDel.Attributes.Add("onclick","returnconfirm('"+"确认删除?

"+"')");

2.linktempDelete.Attributes["onclick"]="javascript:

returnconfirm('"+"确认删除?

"+"');";

3.privatevoidgrdProject_ItemDataBound(objectsender,DataGridItemEventArgse)

4.

{

if((e.Item.ItemType==ListItemType.Item)|(e.Item.ItemType==ListItemType.AlternatingItem))

{

//刪除按鈕上的提示部分

e.Item.Cells[10].Attributes.Add("onclick","returnconfirm('确定删除吗?

');");

}

}

5.

functiondelete_y(e)

{

if(event.srcElement.outerText=="删除")

event.returnValue=confirm("确定删除?

");

}

document.onclick=delete_y;

(三).关闭窗体

1.

this.btnClose.Attributes.Add("onclick","window.close();returnfalse;");

2.关闭本窗体间跳转到另一个页面

this.HyperLink1.NavigateUrl="javascript:

onclick=window.opener.location.assign

('"+"index.aspx"+"?

&Func=Edit&AutoID="+intAutoid+');window.close();";

3.关闭父窗体:

'onclick="window.parent.close()"Class="Button">

4.关闭本弹出窗体,并刷新父页面

this.Response.Write("window.opener.location.reload();window.close();");

5.返回上一页

超链接设置HRef属性:

javascript:

history.back(-1)

(四).WebMessageBox

1.

Response.Write("window.alert('保存成功1');");

2.

Response.Write("");

3.

this.Page.RegisterStartupScript("ChiName","alert('"+"保存成功!

"+"')");

(五).DataGrid中加CheckBox控件模板列.

请看:

(六).window.open()方法

语法:

window.open(pageurl,name,parameters);

window对象的open()方法用于创建一个新的窗口实例,新创建的窗口的外观由参数:

parameters指定。

新窗口中打开的文档由参数:

pageurl指定。

系统能够根据参数:

name确定的名称访问该窗口。

下表为parameters参数表:

参数衩始值说明

alwaysLoweredyes/no指定窗口隐藏在所有窗口之下。

alwaysRaisedyes/no指定窗口浮在所有窗口之上。

dependentyes/no指定打开的窗口为父窗口的一个了窗口。

并随父窗口的关闭而关闭。

directionsyes/no指定Navigator2和3的目录栏是否在新窗口中可见。

heightpixelvalue设定新窗口的像素高度。

hotkeysyes/no在没有菜单栏的新窗口设置安全退出热键。

innerHeightpixelvalue设置新窗口中文档的像素高度。

innerWidthpixelvalue设置新窗口中文档的像素宽度。

locationyes/no指明位置栏在新窗口中是否可见。

menubaryes/no指明菜单栏在新窗口中是否可见。

outerHeightpixelvalue设定窗口(包括装饰边框)的像素高度。

outerWidthpixelvalue设定窗口(包括装饰边框)的像素宽度。

resizableyes/no指明新窗口是否可以调整。

screenXpixelvalue设定新窗口离屏幕边界的像素长度。

screenYpixelvalue设定新窗口离屏幕上边界的像素长度。

scrollbarsyes/no指明滚动栏在新窗口中是否可见。

titlebaryes/no指明菜单题目栏在新窗口是否可见。

toolbaryes/no指明工具栏在新窗口中是否可见。

Widthpixelvalue设定窗口的像素宽度。

z-lookyes/no在文档中包含各个标签的数组。

fullscreenyes/no打开的窗体是否进行全屏显示

leftpixelvalue设定新窗口距屏幕左方的距离

toppixelvalue设定新窗口距屏幕上方的距离

例子:

window.open函数

--

window.open("","name1","width=100,height=200,toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=100");

//-->

divimg{

max-width:

600px;

width:

600px;

width:

expression(document.body.clientWidth>600?

"600px":

"auto");

overflow:

hidden;

}

图片自适应大小

Response.Write("alert('采购单提交成功!

谢谢您的采购!

');location.href='index.htm'");

Response.Write("");

gridview中

Response.Write("alert('修改成功!

');window.history.go(-2);");

document.getElementById("msh2").innerHTML=document.getElementById("Layer1").innerHTML;

25.光标是停在文本框文字的最后

functioncc()

{

 vare=event.srcElement;

 varr=e.createTextRange();

 r.moveStart('character',e.value.length);

 r.collapse(true);

 r.select();

}

3.关闭当前窗口

  <ahref="/"onClick="javascript:

window.close();returnfalse;">关闭窗口</a>

4.5秒后关闭当前页

  <scriptlanguage="Javascript">

  <!

--

  setTimeout('window.close();',5000);

  -->

  </script>

5.2秒后载入指定网页

  <head>

  <metahttp-equiv="refresh"content="2;URL=http:

//你的网址">

  </head>

6.

  /*加入收藏夹*/

functionJSAddFavorite(FavName,FavUrl)

{

if(window.sidebar&&"object"==typeof(window.sidebar)&&"function"==typeof(window.sidebar.addPanel))

{

//firefox

window.sidebar.addPanel(FavName,FavUrl,'');

}

elseif(document.all&&"object"==typeof(window.external))

{

//ie

window.external.AddFavorite(FavUrl,FavName);

}

}

7.让超链接不显示下划线

  <styletype="text/css">

  <!

-

  a:

link{text-decoration:

none}

  a:

hover{text-decoration:

none}

  a:

visited{text-decoration:

none}

  ->

  </style>

9.设置该页为首页

  <bodybgcolor="#FFFFFF"text="#000000">

  <!

--网址:

http:

//你的网址-->

  <aclass="chlnk"style="cursor:

hand"HREF

  onClick="this.style.behavior='url(#default#homepage)';

  this.setHomePage('你的网站名称);"><fontcolor="000000"size="2"face="宋体">设为首页</font></a>

  </body>

10.节日倒计时

  <scriptLanguage="Javascript">

  vartimedate=newDate("December25,2003");

  vartimes="圣诞节";

  varnow=newDate();

  vardate=timedate.getTime()-now.getTime();

  vartime=Math.floor(date/(1000*60*60*24));

  if(time>=0)

  document.write("现在离"+times+"还有:

"+time+"天")</script>

13.显示系统当前日期

  <scriptlanguage=Javascript>

  today=newDate();

  functiondate(){

  this.length=date.arguments.length

  for(vari=0;i<this.length;i++)

  this[i+1]=date.arguments}

  vard=newdate("星期日","星期一","星期二","星期三","星期四","星期五","星期六");

  document.write(

  "<fontcolor=##000000style='font-size:

9pt;font-family:

宋体'>",

  today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日",

  d[today.getDay()+1],"</font>");

  </script>

14.不同时间段显示不同问候语

  <scriptLanguage="Javascript">

  <!

--

  vartext="";day=newDate();time=day.getHours();

  if((time>=0)&&(time<7))

    text="夜猫子,要注意身体哦!

"

  if((time>=7)&&(time<12))

    text="今天天气……哈哈哈,不去玩吗?

"

  if((time>=12)&&(time<14))

    text="午休时间哦,朋友一定是不习惯午睡的吧?

"

  if((time>=14)&&(time<18))

    text="下午茶的时间到了,休息一下吧!

"

  if((time>=18)&&(time<=22))

    text="您又来了,可别和MM聊太久哦!

"

  if((time>=22)&&(time<24))

    text="很晚了哦,注意休息呀!

"

  document.write(text)

  //--->

  </script>

1.oncontextmenu="window.event.returnvalue=false"将彻底屏蔽鼠标右键

no可用于Table

2.取消选取、防止复制

3.onpaste="returnfalse"不准粘贴

4.oncopy="returnfalse;"oncut="returnfalse;"防止复制

5.IE地址栏前换成自己的图标

6.可以在收藏夹中显示出你的图标

7.

disabled">关闭输入法

8.永远都会带着框架

--if(window==top)top.location.href="frames.htm";//frames.htm为框架网页//-->

9.防止被人frame

--if(top.location!

=self.location)top.location=self.location;//-->

10.网页将不能被另存为

15.判断上一页的来源

javascript:

document.referrer

17.屏蔽功能键

Shift,Alt,Ctrl

19.怎样让表单没有凹凸感?

1solid#000000">或

none;border-right:

none;border-top:

none;border-bottom:

1solid#000000">

20.

&的区别?

(division)用来定义大段的页面元素,会产生转行

用来定义同一行内的元素,跟

的唯一区别是不产生转行

是ns的标记,ie不支持,相当于

21.让弹出窗口总是在最上面:

22.不要滚动条?

让竖条没有:

scroll;overflow-y:

hidden">

让横条没有:

scroll;overflow-x:

hidden">

两个都去掉?

更简单了

23.怎样去掉图片链接点击后,图片周围的虚线?

24.电子邮件处理提交表单

25.在打开的子窗口刷新父窗口的代码里如何写?

window.opener.location.reload()

26.如何设定打开页面的大小

打开页面的位置

35.ENTER键可以让光标移到下一个输入框

1.文本框焦点问题

onBlur:

当失去输入焦点后产生该事件

onFocus:

当输入获得焦点后,产生该文件

Onchange:

当文字值改变时,产生该事件

Onselect:

当文字加亮后,产生该文件

9.状态栏显示该页状态

46.可以下载文件

document.location.href="目标文件"//

70.截取小数点后两位

vara=3454545.4454545;

alert(a.toFixed

(2));//

82.event.x,event.clientX,event.offsetX区别:

x:

设置或者是得到鼠标相对于目标事件的父元素的外边界在x坐标上的位置。

clientX:

相对于客户区域的x坐标位置,不

包括滚动条,就是正文区域。

offsetx:

设置或者是得到鼠标相对于目标事件的父元素的内边界在x坐标上的位置。

screenX:

相对于用户屏幕。

170.正则表达式

////////利用正则表达式分解和转换IP地址:

下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的Javascript程序:

functionIP2V(ip)

{

re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g//匹配IP地址的正则表达式

if(re.test(ip))

{

returnRegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1

}

else

{

thrownewError("NotavalidIPaddress!

")

}

}

不过上面的程序如果不用正则表达式,而直接用split函数来分解可能更简单,程序如下:

varip="10.100.20.168"

ip=ip.split(".")

alert("IP值是:

"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))

程序代码

'*******************************************************************

'检测是否是手机浏览

'*******************************************************************

<%

ifinstr(request.ServerVariables("HTTP_USER_AGENT"),"Mozilla")=0then

response.redirect"/wap"'如果客户端为手机访问,则进入/wap目录

else

response.redirect""'如果客户端不是手机访问,则进入指定地址

endif

%>

程序代码

'*******************************************************************

'取得IP地址

'*****************************************************

展开阅读全文
相关搜索

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1