JavaScript使用技巧精.docx
- 文档编号:30660086
- 上传时间:2023-08-19
- 格式:DOCX
- 页数:23
- 大小:26.69KB
JavaScript使用技巧精.docx
《JavaScript使用技巧精.docx》由会员分享,可在线阅读,更多相关《JavaScript使用技巧精.docx(23页珍藏版)》请在冰豆网上搜索。
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.关闭父窗体:
4.关闭本弹出窗体,并刷新父页面
this.Response.Write("
5.返回上一页
超链接设置HRef属性:
javascript:
history.back(-1)
(四).WebMessageBox
1.
Response.Write("
2.
Response.Write("");
3.
this.Page.RegisterStartupScript("ChiName","
"+"')");
(五).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("","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("
谢谢您的采购!
');location.href='index.htm'");
Response.Write("");
gridview中
Response.Write("
');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"将彻底屏蔽鼠标右键
2. 3.onpaste="returnfalse"不准粘贴 4.oncopy="returnfalse;"oncut="returnfalse;"防止复制 5. 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. 用来定义同一行内的元素,跟 21.让弹出窗口总是在最上面: 22.不要滚动条? 让竖条没有: scroll;overflow-y: hidden">no可用于Table