Chinaunix首页 | 论坛 | 博客
  • 博客访问: 929943
  • 博文数量: 210
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2070
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-19 21:54
文章分类

全部博文(210)

文章存档

2020年(2)

2019年(18)

2018年(27)

2017年(5)

2016年(53)

2015年(88)

2014年(17)

分类: JavaScript

2017-06-12 09:44:03

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

no
可用于Table
2. 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="return false;" 防止复制
5. IE地址栏前换成自己的图标
6. 可以在收藏夹中显示出你的图标
7. 关闭输入法

8. 永远都会带着框架 

1
2
3
  

9. 防止被人frame 

1
2
3
  

10. 网页将不能被另存为 

1

11.

1
onclick="window.location = "view-source:"+ "http://www.pconline.com.cn"">

12.删除时确认 

1
删除 

13. 取得控件的绝对位置 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//Javascript 
 
function getIE(e){ 
var t=e.offsetTop; 
var l=e.offsetLeft; 
while(e=e.offsetParent){ 
t+=e.offsetTop; 
l+=e.offsetLeft; 
alert("top="+t+"/nleft="+l); 
 
//VBScript 
  

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

1
2
3
4
5
6
7
8
9
10
11
 
function cc() 
var e = event.srcElement; 
var r =e.createTextRange(); 
r.moveStart("character",e.value.length); 
r.collapse(true); 
r.select(); 
 

15. 判断上一页的来源 

1
2
javascript : 
document.referrer

16. 最小化、最大化、关闭窗口 

1
2
3
4
5
6
7
8
9
10
 
  
 
  
 
  
 
 
 
本例适用于IE

17.屏蔽功能键Shift,Alt,Ctrl 

1
2
3
4
5
6
7

18. 网页不会被缓存 

1
2
3
4
 
 
 
或者 

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

1
2
3
4
 
或 
1 solid #000000"> 

20.

& 的区别? 

1
2
3
(division)用来定义大段的页面元素,会产生转行 
用来定义同一行内的元素,跟 
的唯一区别是不产生转行 
是ns的标记,ie不支持,相当于 

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

1

22.不要滚动条? 

1
2
3
4
5
6
7
8
9
让竖条没有: 
 
 
让横条没有: 
 
 
两个都去掉?更简单了 
 

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

1
  

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

1
2
3
4
enctype="text/plain"> 
 

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

1
window.opener.location.reload()

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

1
2
 
打开页面的位置 

27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动 

1
2
3
4
5

28. 检查一段字符串是否全由数字组成 

1
2
3
4
5
  

29. 获得一个窗口的大小 

1
document.body.clientWidth; document.body.clientHeight

30. 怎么判断是否是字符 

1
2
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字"); 
else alert("全是字符");

31.TEXTAREA自适应文字行数的多少 

1
2
3
="this.style.posHeight=this.scrollHeight"> 

32. 日期减去天数等于第二个日期 

1
2
3
4
5
6
7
8
9
10
11
12
 
function cc(dd,dadd) 
//可以加上错误处理 
var a = new Date(dd) 
a = a.valueOf() 
a = a - dadd * 24 * 60 * 60 * 1000 
a = new Date(a) 
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日") 
cc("12/23/2002",2) 

33. 选择了哪一个Radio 

1
2
3
4
5
6
7
8
9
10
11
12
  
function checkme() 
for each ob in radio1 
if ob.checked then 
window.alert ob.value 
next 
end function 
  
Style 
Barcode 
 

34.脚本永不出错 

1
2
3
4
5
6
7
8
 
 

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

1

36. 检测某个网站的链接速度: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
把如下代码加入 区域中: 
 
tim=1 
setInterval("tim++",100) 
b=1 
var autourl=new Array() 
autourl[1]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.njcatv.net" 
autourl[2]="javacool.3322.net" 
autourl[3]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.sina.com.cn" 
autourl[4]="www.nuaa.edu.cn" 
autourl[5]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.cctv.com" 
function butt(){ 
***(" ") 
for(var i=1;i 
***("  =》 
name=url"+i+" size=40> =》 
onclick=window.open(this.form.url"+i+".value)> 
") 
***("  ") 
butt() 
function auto(url){ 
document.forms[0]["url"+b].value=url 
if(tim>200) 
{document.forms[0]["txt"+b].value="/链接超时"} 
else 
{document.forms[0]["txt"+b].value="/blog/时间"+tim/10+"秒"} 
b++ 
function run(){for(var i=1;i 
onerror=auto("http://"+autourl+"")>")} 
run() 

37. 各种样式的光标 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
auto :标准光标 
default :标准箭头 
hand :手形光标 
wait :等待光标 
text :I形光标 
vertical-text :水平I形光标 
no-drop :不可拖动光标 
not-allowed :无效光标 
help :?帮助光标 
all-scroll :三角方向标 
move :移动标 
crosshair :十字标 
e-resize 
n-resize 
nw-resize 
w-resize 
s-resize 
se-resize 
sw-resize

38.页面进入和退出的特效 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
进入页面  
推出页面  
这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23: 
0 矩形缩小 
1 矩形扩大 
2 圆形缩小 
3 圆形扩大 
4 下到上刷新 
5 上到下刷新 
6 左到右刷新 
7 右到左刷新 
8 竖百叶窗 
9 横百叶窗 
10 错位横百叶窗 
11 错位竖百叶窗 
12 点扩散 
13 左右到中间刷新 
14 中间到左右刷新 
15 中间到上下 
16 上下到中间 
17 右下到左上 
18 右上到左下 
19 左上到右下 
20 左下到右上 
21 横条 
22 竖条 
23 以上22种随机选择一种

39.在规定时间内跳转 

1

40.网页是否被检索 

1
2
3
4
5
6
7
8
 
其中属性值有以下一些: 
属性值为"all": 文件将被检索,且页上链接可被查询; 
属性值为"none": 文件不被检索,而且不查询页上的链接; 
属性值为"index": 文件将被检索; 
属性值为"follow": 查询页上的链接; 
属性值为"noindex": 文件不检索,但可被查询链接; 
属性值为"nofollow": 文件不被检索,但可查询页上的链接。

41、email地址的分割 

1
2
把如下代码加入 区域中 
webmaster@sina.com 


42、流动边框效果的表格 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
把如下代码加入 区域中 

43、JavaScript主页弹出窗口技巧 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
窗口中间弹出 
 
============ 
 
 
 
function WinOpen() { 
msg=open("","DisplayWindow","toolbar=no,directories=no,menubar=no"); 
msg.***("  哈 罗!  "); 
msg.***(" 
 

酷 毙 了! 

 

这 是 JavaScript 所 开 的 视 窗! 

 
"); 
 
 
 
 
 
 
 
============== 
一、在下面的代码中,你只要单击打开一个窗口,即可链接到赛迪网。而当你想关闭时,只要单击一下即可关闭刚才打开的窗口。 
代码如下: 
 
<!-- 
function openclk() { 
another=open(‘1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>http://www.ccidnet.com‘,‘NewWindow‘); 
function closeclk() { 
another.close(); 
//--> 
 
 
 

 
 
 
二、上面的代码也太静了,为何不来点动感呢?如果能给页面来个降落效果那该多好啊! 
代码如下: 
 
 
三、讨厌很多网站总是按照默认窗口打开,如果你能随心所欲控制打开的窗口那该多好。 
代码如下: 
 
<!-- Begin 
function popupPage(l, t, w, h) { 
var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes" + 
",left=" + l + ",top=" + t + ",width=" + w + ",height=" + h; 
var URL = "http://www.80cn.com"; 
popup = window.open(URL,"MenuPopup",windowprops); 
// End --> 
 
 
 
 
 
 
 
 
							
打开页面的参数 
 
离开左边的距离:  pixels 
离开右边的距离:  pixels 
窗口的宽度:  pixels 
窗口的高度:  pixels 
 
 
this.form.height.value)"> 
 
 
你只要在相对应的对话框中输入一个数值即可,将要打开的页面的窗口控制得很好。

44、页面的打开移动 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
把如下代码加入 区域中 
 
 
// End --> 

45、显示个人客户端机器的日期和时间 

1
2
3
4
5
6
7
 
 

46、自动的为你每次产生最後修改的日期了: 

1
2
3
4
5
6
7
8
9
10
11
12
 
 
This is a simple HTML- page. 

 
Last changes: 
 
 
 
 

47、不能为空和邮件地址的约束: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
 
 
 
 
 
 
 
Enter your name: 
 
 
 

 

Enter your e-mail address: 
 
 
 

48、跑马灯 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
 
 
 
 
 
 
这里可显示您的网页 ! 
 

49、在网页中用按钮来控制前页,后页和主页的显示。 

1
2
3
4
5
6
7
8
9
 
 
 
 
 
 
 
 

50、查看某网址的源代码 

1
2
3
4
5
6
7
8
9
10
11
12
13
把如下代码加入 区域中 
 
输入要查看源代码的URL地址: 
   
 
 
 

51、title显示日期 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
把如下代码加入 区域中: 
 
 

52、显示所有链接 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
把如下代码加入 区域中 
 
 
 

53、回车键换行 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
把如下代码加入 区域中 
 
function handleEnter (field, event) { 
var keyCode = event.keyCode ? event.keyCode : event.which ? 
event.which : event.charCode; 
if (keyCode == 13) { 
var i; 
for (i = 0; i < field.form.elements.length; i++) 
if (field == field.form.elements) 
break; 
i = (i + 1) % field.form.elements.length; 
field.form.elements.focus(); 
return false; 
else 
return true; 
 
 
 
 
 
 
'; tpl += '
'; tpl += '
'; tpl += '
'; tpl += ''; tpl += '
'; tpl += '
'; tpl += '
'; $('.z_move_comment').html(''); $(this).parents('.Blog_right1_8').find('.z_move_comment').html(tpl).show(); }); //引用的评论提交 $('#quota_sbumit').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var tid = $(this).attr('tid');//被引用人的id var qid = $(this).attr('cid');//引用的id var url = $(this).attr('url'); var text = $('#rmsg').val(); var tname = $(this).attr('tname'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : tid , 'qid' : qid , 'text': text , 'tname' : tname }, dataType: 'json', success: function(data){ if(data.code == 1){ var tpl = '
'; tpl+= ''; tpl+= '
'; tpl+= '

' + data.info.username + '' + data.info.dateline + '

'; tpl+= '

' + data.info.quota.username + ':'+ data.info.quota.content + '

'; tpl+= '

' + data.info.content + '

回复 |  删除 |  举报
'; tpl+= ''; tpl+= '
'; $('#replyList .Blog_right1_8:first').before(tpl); $('.z_move_comment').html('').hide(); } else if(data.code == -1){ //showErrorMsg(data.info , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } }, error: function(){//请求出错处理 } }); }); //底部发表评论 $('#submitmsg').click(function(){ if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var bid = $(this).attr('bid'); var toid = $(this).attr('toid'); var text = $('#reply').val(); var url = $(this).attr('url'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : toid ,'text': text}, dataType: 'json', success: function(data){ if(data.code == 1) { var tpl = '
'; tpl += ''; tpl += '
'; tpl += '

' + data.info.username + '' + data.info.dateline + '

'; tpl += '

' + data.info.content + '

'; tpl += '
回复 |  删除 |  举报
'; tpl += ''; tpl += '
'; $('.Blog_tit3:first').after(tpl); $('#reply').val('文明上网,理性发言...'); } else if(data.code == -1) { showErrorMsg(data.info , '消息提示'); } }, error: function(){//请求出错处理 } }); }); //底部评论重置 $('#reset_comment').click(function(){ $('#reply').val('文明上网,理性发言...'); }); //取消回复 $('#qx_comment').live('click' , function(){ $('.z_move_comment').html('').hide(); }); $('#rmsg, #reply').live({ focus:function(){ if($(this).val() == '文明上网,理性发言...'){ $(this).val(''); } }, blur:function(){ if($(this).val() == ''){ $(this).val('文明上网,理性发言...'); } } }); //删除留言确认 $('.comment_del_mark').live('click' , function(){ var url = $(this).attr('url'); asyncbox.confirm('删除留言','确认', function(action){ if(action == 'ok') { location.href = url; } }); }); //删除时间确认 $('.del_article_id').click(function(){ var delurl = $(this).attr('delurl'); asyncbox.confirm('删除文章','确认', function(action){ if(action == 'ok') { location.href = delurl; } }); }); /* //字数限制 $('#rmsg, #reply').live('keyup', function(){ var id = $(this).attr('id'); var left = Util.calWbText($(this).val(), 500); var eid = '#errmsg'; if(id == 'reply') eid = '#rerrmsg'; if (left >= 0) $(eid).html('您还可以输入' + left + '字'); else $(eid).html('您已超出' + Math.abs(left) + ''); }); */ //加载表情 $('#face').qqFace({id : 'facebox1', assign : 'reply', path : '/image/qqface/'}); $('#mface').qqFace({id : 'facebox', assign : 'rmsg', path:'/image/qqface/'}); /* $('#class_one_id').change(function(){ alert(123213); var id = parseInt($(this).val() , 10); if(id == 0) return false; $('.hidden_son_class span').each(function( index , dom ){ if( dom.attr('cid') == id ) { } }); }); */ //转载文章 var turn_url = "/blog/viewClassPart.html"; $('#repost_bar').click(function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var id = $(this).attr('bid'); asyncbox.open({ id : 'turn_class_thickbox', url : turn_url, title : '转载文章', width : 330, height : 131, scroll : 'no', data : { 'id' : id }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); /* //转发文章 $('#repost_bar').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var url = $(this).attr('url'); asyncbox.confirm('转载文章','确认', function(action){ if(action == 'ok'){ $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0){ showSucceedMsg('转发成功!', '消息提示'); }else if(msg.error == 1){ //location.href = '/index.php?r=site/login'; showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); }else{ showErrorMsg(msg.error_content, '消息提示'); } } }); } }); }); */ });