javascript
1. 屏蔽鼠标右键
oncontextmenu="window.event.returnValue=false"
no |
2. 无法选取、禁止复制
3. 禁止复制
oncopy="return false;" oncut="return false;"
4. 禁止粘贴
onpaste="return false"
5. 最小化、最大化、关闭窗口
本例适用于IE
6. 让表单没有凹凸感
或
7. 去掉滚动条
去掉竖条:
去掉横条:
两个都不要:
8. 去掉图片链接点击后,图片周围的虚线
9. 在打开的子窗口刷新父窗口的代码
window.opener.location.reload()
10. 设定新开页面的大小
打开页面的位置
11. 在页面中加入背景,拉动页面时背景图不动
body
{background-image:url(logo.gif); background-repeat:no-repeat;
background-position:center;background-attachment: fixed}
12. TEXTAREA自适应文字行数的多少
13. 网页将不能被另存为
14. 单击鼠标右键弹出添加收藏夹对话框
在
之间加上如下代码:if (document.all)
document.body.onmousedown=new Function("if
(event.button==2||event.button==3)
window.external.addFavorite('您的网址','您的网站名称)")
15. 随机变换背景图象
在
之间加上如下代码:image = new Array(4); //定义image为图片数量的数组
image [0] = 'tu0.gif' //背景图象的路径
image [1] = 'tu1.gif'
image [2] = 'tu2.gif'
image [3] = 'tu3.gif'
image [4] = 'tu4.gif'
number = Math.floor(Math.random() * image.length);
document.write("
");16. 关闭当前窗口
17. 2秒后关闭当前页
18. 2秒后载入指定网页
19. 改变滚动条的颜色
BODY {
SCROLLBAR-FACE-COLOR: #000048;
SCROLLBAR-HIGHLIGHT-COLOR: #d82448;
SCROLLBAR-SHADOW-COLOR: #fcd8d8;
SCROLLBAR-3DLIGHT-COLOR: #fc0000;
SCROLLBAR-ARROW-COLOR: #fcfc48;
SCROLLBAR-TRACK-COLOR: #4848fc;
SCROLLBAR-DARKSHADOW-COLOR: #489024;
SCROLLBAR-BASE-COLOR: #482448
}
20. REALONE播放器镶嵌页面的代码
21. 指定位置随机图片显示
a = 3
var slump = Math.random();
var talet = Math.round(slump * (a-1))+1;
function create() {
this.src = ''
this.border = ''
this.alt = ''
}
b = new Array()
for(var i=1; i<=a; i++) { b[i] = new create() }
b[1].src = "../pic/pic01.gif"
b[1].border = "0"
b[1].alt = "图形一"
b[2].src = "../pic/pic02.gif"
b[2].border = "0"
b[2].alt = "图形二"
b[3].src = "../pic/pic03.gif"
b[3].border = "0"
b[3].alt = "图形三"
var visa = "";
visa += '';
22. window.open() 支持环境,语法,参数,例子(详细)
① window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+
② 基本语法:
window.open(pageURL,name,parameters)
其中:
pageURL 为子窗口路径
name 为子窗口句柄
parameters 为窗口参数(各参数用逗号分隔)
③ 各项参数
其中yes/no也可使用1/0;pixel value为具体的数值,单位象素
参数取值范围说明
alwaysLowered yes/no 指定窗口隐藏在所有窗口之后alwaysRaised yes/no 指定窗口悬浮在所有窗口之上
depended yes/no 是否和父窗口同时关闭
directories yes/no Nav2和3的目录栏是否可见
height pixel value 窗口高度
hotkeys yes/no
在没菜单栏的窗口中设安全退出热键
innerHeight pixel value 窗口中文档的像素高度innerWidth pixel value 窗口中文档的像素宽度location yes/no 位置栏是否可见menubar yes/no 菜单栏是否可见
outerHeight pixel value
设定窗口(包括装饰边框)的像素高度
outerWidth pixel value
设定窗口(包括装饰边框)的像素宽度
resizable yes/no 窗口大小是否可调整screenX pixel value 窗口距屏幕左边界的像素长度screenY pixel value 窗口距屏幕上边界的像素长度scrollbars yes/no 窗口是否可有滚动栏
titlebar yes/no 窗口题目栏是否可见
toolbar yes/no 窗口工具栏是否可见
Width pixel value 窗口的像素宽度
z-look yes/no
窗口被激活后是否浮在其它窗口之上
④ 例子:
脚本运行后,page.html将在新窗体newwindow中打开,宽为100,高为400,距屏顶0象素,
屏左0象素,无工具条,无菜单条,无滚动条,不可调整大小,无地址栏,无状态栏
Added by Admin (2005-9-30 1:43:48) 动态加css文件:document.createStyleSheet("xxx.css")
为某个对象写style:obj.cssText
obj.all.tags("table") //查找所有obj中包含的table
obj.children.getElementByTagName("标签名称") xml中
创建web对象
function addElement(p,el){ return
p.appendChild(element.document.createElement(el)); }
Event 事件
事件源对象
event.srcElement.tagName
event.srcElement.type
捕获释放
event.srcElement.setCapture();
event.srcElement.releaseCapture();
事件按键
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
事件返回值
event.returnValue
鼠标位置
event.x
event.y
document 对象
窗体活动元素
document.activeElement
绑定事件
document.captureEvents(Event.KEYDOWN);
访问窗体元素
document.all("txt").focus();
document.all("txt").select();
窗体命令
document.execCommand
窗体COOKIE
document.cookie
菜单事件
document.oncontextmenu
创建元素
document.createElement("SPAN");
根据鼠标获得元素
document.elementFromPoint(event.x,event.y).tagName=="TD" document.elementFromPoint(event.x,event.y).appendChild(ms) 窗体图片
document.images[索引]
窗体事件绑定
document.onmousedown=scrollwindow;
元素
document.窗体.elements[索引]
对象绑定事件
document.all.xxx.detachEvent('onclick',a);
HTML标签
document.documentElement.innerHTML
第一个style标签
document.styleSheets[0]
style标签里的第一个样式
document.styleSheets[0].rules[0]
获取选中内容
document.selection.createRange().duplicate().text
插件数目
navigator.plugins
取变量类型
typeof($js_libpath) == "undefined"
下拉框
下拉框.options[索引]
下拉框.options.length
查找对象
document.getElementsByName("r1");
document.getElementById(id);
定时
timer=setInterval('scrollwindow()',delay);
clearInterval(timer);
UNCODE编码
escape(),unescape
父对象
obj.parentElement(dhtml)
obj.parentNode(dom)
交换表的行
TableID.moveRow(2,1)
替换CSS
document.all.csss.href = "a.css";
并排显示
display:inline
隐藏焦点
hidefocus=true
根据宽度换行
style="word-break:break-all"
让英文字符串超出表格宽度自动换行
word-wrap: break-word; word-break: break-all;
框架透明背景
获得style内容
obj.style.cssText
自动刷新
简单邮件
快速转到位置
obj.scrollIntoView(true)
锚
网页传递参数
location.search();
可编辑
obj.contenteditable=true
执行菜单命令
obj.execCommand
双字节字符
/[^\x00-\xff]/
汉字
/[\u4e00-\u9fa5]/
防止点击空链接时,页面往往重置到页首端
上一网页源
asp:request.servervariables("HTTP_REFERER")
javascript:document.referrer
释放内存
CollectGarbage();
禁止右键
document.oncontextmenu = function() { return false;}
禁止保存
禁止选取
oncopy="document.selection.empty()" onbeforecopy="return
false"onmouseup="document.selection.empty()>
禁止粘贴
地址栏图标
favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
收藏栏图标
查看源码
关闭输入法
自动全选
ENTER键可以让光标移到下一个输入框
文本框的默认值
checkbox扁平
自动完成功能
打开该功能
关闭该功能
title换行
obj.title = "123 sdfs "
获得时间所代表的微秒
var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
窗口是否关闭
win.closed
窗口最大化
无关闭按钮IE
window.open("aa.htm", "meizz", "fullscreen=7");
统一编码/解码
alert(decodeURIComponent(encodeURIComponent("https://www.360docs.net/doc/904126750.html,/s?wd=阿飞"))) encodeURIComponent对":"、"/"、";" 和 "?"也编码
表格行指示
各种尺寸
s += "\r\n网页可见区域宽:"+ document.body.clientWidth;
s += "\r\n网页可见区域高:"+ document.body.clientHeight;
s += "\r\n网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)";
s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;
s += "\r\n网页正文全文高:"+ document.body.scrollHeight;
s += "\r\n网页被卷去的高:"+ document.body.scrollTop;
s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;
s += "\r\n网页正文部分上:"+ window.screenTop;
s += "\r\n网页正文部分左:"+ window.screenLeft;
s += "\r\n屏幕分辨率的高:"+ window.screen.height;
s += "\r\n屏幕分辨率的宽:"+ window.screen.width;
s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;
s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;
过滤数字
特殊用途
onclick="window.external.ImportExportFavorites(true,'https://www.360docs.net/doc/904126750.html,/');">
onclick="window.external.ImportExportFavorites(false,'https://www.360docs.net/doc/904126750.html,/');" >
onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)">
onclick="window.external.ShowBrowserUI('LanguageDialog', null)">
onclick="window.external.AddFavorite('https://www.360docs.net/doc/904126750.html,/', 'google')">
onclick="window.external.addChannel('https://www.360docs.net/doc/904126750.html,/')">
onclick="window.external.showBrowserUI('PrivacySettings',null)">
不缓存
正则匹配
匹配中文字符的正则表达式: [\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内):[^\x00-\xff]
匹配空行的正则表达式:\n[\s| ]*\r
匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/
匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim击数)
匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
以下是例子:
利用正则表达式限制网页表单里的文本框输入内容:
用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-
\u9FA5]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replac e(/[^\u4E00-\u9FA5]/g,''))"
1. 用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^\uFF00-
\uFFFF]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replac e(/[^\uFF00-\uFFFF]/g,''))"
2. 用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').repla ce(/[^\d]/g,''))"
3. 用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').repla ce(/[^\d]/g,''))"
消除图像工具栏
or
无提示关闭
function Close(){
var ua=https://www.360docs.net/doc/904126750.html,erAgent
var ie=navigator.appName=="Microsoft Internet Explorer"?true:false
if(ie)
{
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE
")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
if(IEversion< 5.5)
{
var str = '
str += '';
document.body.insertAdjacentHTML("beforeEnd", str);
document.all.noTipClose.Click();
}
else
{
window.opener =null;
window.close();
}
}
else
{
window.close()
}
}
取得控件得绝对位置
function getoffset(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent)
{
t+=e.offsetTop;
l+=e.offsetLeft;
}
var rec = new Array(1);
rec[0] = t;
rec[1] = l;
return rec
}
最小化,最大化,关闭
光标停在文字最后
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart('character',e.value.length);
r.collapse(true);
r.select();
}
页面进入和退出的特效
进入页面
推出页面
这个是页面被载入和调出时的一些特效。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
网页是否允许被搜索引擎机器人检索
其中属性值有以下一些:
属性值为"all": 文件将被检索,且页上链接可被查询;
属性值为"none": 文件不被检索,而且不查询页上的链接;
属性值为"index": 文件将被检索;
属性值为"follow": 查询页上的链接;
属性值为"noindex": 文件不检索,但可被查询链接;
属性值为"nofollow": 全部不允许。
打印分页
page1
page2
设置打印
onclick=document.all.WebBrowser.ExecWB(7,1)>
去掉打印时的页眉页脚
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//设置网页打印的页眉页脚为空
function PageSetup_Null()
{
try
{
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
}
catch(e){}
}
设置网页打印的页眉页脚为默认值
function PageSetup_Default()
{
try
{
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}
catch(e){}
}
浏览器验证
function checkBrowser()
{
this.ver=navigator.appVersion
this.dom=document.getElementById?1:0
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(https://www.360docs.net/doc/904126750.html,yers && !this.dom)?1:0;
this.mac=(this.ver.indexOf('Mac') > -1) ?1:0;
this.ope=(https://www.360docs.net/doc/904126750.html,erAgent.indexOf('Opera')>-1);
this.ie=(this.ie6 || this.ie5 || this.ie4)
this.ns=(this.ns4 || this.ns5)
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope)
this.nbw=(!this.bw)
return this;
}
计算内容宽和高
function test(obj)
{
var range = obj.createTextRange();
alert("内容区宽度: " + range.boundingWidth + "px\r\n内容区高度: " +
range.boundingHeight + "px");
}
无模式的提示框
function modelessAlert(Msg)
{window.showModelessDialog("javascript:alert(\""+escape(Msg)+"\");window.close() ;","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px ;");
}
屏蔽按键
屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键
JAVASCRIPT 笔试必考题
JavaScript笔试必考题 答案在最后 1) Output------? a)44 b)8 c)4 d)Error output 2) a)Quality b)Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s c)Qualiyt,Point,Technologies d)QualityPointTechnologies 3)Is it possible to nest functions in JavaScript? a)True b)False 4)
a)get code name of the browser of a visitor b)set code name of the browser of a visitor c)None of the above 5)Which of the following is true? a)If onKeyDown returns false,the key-press event is cancelled. b)If onKeyPress returns false,the key-down event is cancelled. c)If onKeyDown returns false,the key-up event is cancelled. d)If onKeyPress returns false,the key-up event is canceled. 6)Scripting language are a)High Level Programming language b)Assembly Level programming language c)Machine level programming language 7)Which best explains getSelection()? a)Returns the VALUE of a selected OPTION. b)Returns document.URL of the window in focus. c)Returns the value of cursor-selected text d)Returns the VALUE of a checked radio input. 8)
Javascript鼠标触发事件大全
Javascript鼠标事件大全 一般事件 事件浏览器支持描述 onClick IE3|N2|O3 鼠标点击事件,多用在某个对象控制的范围内的鼠标点击 onDblClick IE4|N4|O 鼠标双击事件onMouseDown IE4|N4|O 鼠标上的按钮被按下了onMouseUp IE4|N4|O 鼠标按下后,松开时激发的事件 onMouseOver IE3|N2|O3 当鼠标移动到某对象范围的上方时触发的事件 onMouseMove IE4|N4|O 鼠标移动时触发的事件 onMouseOut IE4|N3|O3 当鼠标离开某对象范围时触发的事件 onKeyPress IE4|N4|O 当键盘上的某个键被按下并且释放时触发的事件.[注意:页面内必须有被聚焦的对象] onKeyDown IE4|N4|O 当键盘上某个按键被按下时触发的事件[注意:页面内必须有被聚焦的对象] onKeyUp IE4|N4|O 当键盘上某个按键被按放开时触发的事件[注意:页面内必须有被聚焦的对象] 页面相关事件 事件浏览器支持描述 onAbort IE4|N3|O 图片在下载时被用户中断 onBeforeUnload IE4|N|O 当前页面的内容将要被改变时触发的事件 onError IE4|N3|O 捕抓当前页面因为某种原因而出现的错误,如脚本错误与外部数据引用的错误 onLoad IE3|N2|O3 页面内空完成传送到浏览器时触发的事件,包括外部文件引入完成 onMove IE|N4|O 浏览器的窗口被移动时触发的事件onResize IE4|N4|O 当浏览器的窗口大小被改变时触发
用Js脚本实现页面跳转
1. Javascript 返回上一页 history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.forward()返回下一页 4. window.history.go(返回第几页,也可以使用访问过的URL) 例: 向上一页 response.Write("") response.Write("") 向上一页 页面跳转:onclick="window.location.href='list.aspx'" P.S. 小技巧(JS引用JS): Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand('Refresh') 6 window.navigate(location) 7 location.replace(location) 8 document.URL=location.href 自动刷新页面的方法: 1.页面自动刷新:把如下代码加入
区域中 其中20指每隔20秒刷新一次页面.javascript练习题1
习题1 一、单选题 1、向HTML 页面嵌入JavaScript 脚本描述正确的是( C)。 A.JavaScript 脚本只能放置在HTML 页面中
与中 B.JavaScript 脚本可以放置在HTML 页面中的任何地方 C.JavaScript 脚本必须被标签对所包含 D. JavaScript 脚本必须被