javascript小技巧(转)

来源:互联网 发布:ubuntu 改变用户组 编辑:程序博客网 时间:2024/06/08 16:48

<textarea cols="50" rows="15" name="code" class="javascript"># 事件源对象event.srcElement.tagNameevent.srcElement.type# 捕获释放event.srcElement.setCapture(); event.srcElement.releaseCapture(); # 事件按键event.keyCodeevent.shiftKeyevent.altKeyevent.ctrlKey# 事件返回值event.returnValue# 鼠标位置event.xevent.y# 窗体活动元素document.activeElement# 绑定事件document.captureEvents(Event.KEYDOWN);# 访问窗体元素document.all(&quot;txt&quot;).focus();document.all(&quot;txt&quot;).select();# 窗体命令document.execCommand# 窗体COOKIEdocument.cookie# 菜单事件document.oncontextmenu# 创建元素document.createElement(&quot;SPAN&quot;); # 根据鼠标获得元素:document.elementFromPoint(event.x,event.y).tagName==&quot;TDdocument.elementFromPoint(event.x,event.y).appendChild(ms) # 窗体图片document.images[索引]# 窗体事件绑定document.onmousedown=scrollwindow;# 元素document.窗体.elements[索引]# 对象绑定事件document.all.xxx.detachEvent('onclick',a);# 插件数目navigator.plugins# 取变量类型typeof($js_libpath) == &quot;undefined&quot;# 下拉框下拉框.options[索引]下拉框.options.length# 查找对象document.getElementsByName(&quot;r1&quot;);document.getElementById(id);# 定时timer=setInterval('scrollwindow()',delay);clearInterval(timer);# UNCODE编码escape() ,unescape# 父对象obj.parentElement(dhtml)obj.parentNode(dom)# 交换表的行TableID.moveRow(2,1)# 替换CSSdocument.all.csss.href = &quot;a.css&quot;;# 并排显示display:inline# 隐藏焦点hidefocus=true# 根据宽度换行style=&quot;word-break:break-all&quot;# 自动刷新&lt;meta HTTP-EQUIV=&quot;refresh&quot; CONTENT=&quot;8;URL=http://c98.yeah.net&quot;&gt;# 简单邮件&lt;a href=&quot;mailto:aaa@bbb.com?subject=ccc&amp;body=xxxyyy&quot; mce_href=&quot;mailto:aaa@bbb.com?subject=ccc&amp;body=xxxyyy&quot;&gt; # 快速转到位置obj.scrollIntoView(true)# 锚&lt;a name=&quot;first&quot;&gt;&lt;a href=&quot;#first&quot; mce_href=&quot;#first&quot;&gt;anchors&lt;/a&gt;# 网页传递参数location.search();# 可编辑obj.contenteditable=true# 执行菜单命令obj.execCommand# 双字节字符/[^/x00-/xff]/汉字/[/u4e00-/u9fa5]/# 让英文字符串超出表格宽度自动换行word-wrap: break-word; word-break: break-all;# 透明背景&lt;IFRAME src=&quot;1.htm&quot; mce_src=&quot;1.htm&quot; width=300 height=180 allowtransparency&gt;&lt;/iframe&gt;# 获得style内容obj.style.cssText# HTML标签document.documentElement.innerHTML# 第一个style标签document.styleSheets[0]# style标签里的第一个样式document.styleSheets[0].rules[0]# 防止点击空链接时,页面往往重置到页首端。&lt;a href=&quot;javascript:function()&quot; mce_href=&quot;javascript:function()&quot;&gt;word&lt;/a&gt;# 上一网页源asp:request.servervariables(&quot;HTTP_REFERER&quot;)javascript:document.referrer# 释放内存CollectGarbage();# 禁止右键document.oncontextmenu = function() { return false;}# 禁止保存&lt;noscript&gt;&lt;iframe src=&quot;*.htm&quot; mce_src=&quot;*.htm&quot;&gt;&lt;/iframe&gt;&lt;/noscript&gt;# 禁止选取&lt;body oncontextmenu=&quot;return false&quot; ondragstart=&quot;return false&quot; onselectstart =&quot;return false&quot; onselect=&quot;document.selection.empty()&quot; oncopy=&quot;document.selection.empty()&quot; onbeforecopy=&quot;return false&quot;onmouseup=&quot;document.selection.empty()&gt; # 禁止粘贴&lt;input type=text onpaste=&quot;return false&quot;&gt;# 地址栏图标&lt;link rel=&quot;Shortcut Icon&quot; href=&quot;favicon.ico&quot; mce_href=&quot;favicon.ico&quot;&gt;favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下# 收藏栏图标&lt;link rel=&quot;Bookmark&quot; href=&quot;favicon.ico&quot; mce_href=&quot;favicon.ico&quot;&gt;# 查看源码&lt;input type=button value=查看网页源代码 onclick=&quot;window.location = 'view-source:'+ 'http://www.csdn.net/'&quot;&gt;# 关闭输入法&lt;input style=&quot;ime-mode:disabled&quot; mce_style=&quot;ime-mode:disabled&quot;&gt;# 自动全选&lt;input type=text name=text1 value=&quot;123&quot; onfocus=&quot;this.select()&quot;&gt;# ENTER键可以让光标移到下一个输入框&lt;input onkeydown=&quot;if(event.keyCode==13)event.keyCode=9&quot;&gt;# 文本框的默认值&lt;input type=text value=&quot;123&quot; onfocus=&quot;alert(this.defaultValue)&quot;&gt;# title换行obj.title = &quot;123sdfs &quot;# 获得时间所代表的微秒var n1 = new Date(&quot;2004-10-10&quot;.replace(/-/g, &quot;//&quot;)).getTime()# 窗口是否关闭win.closed# checkbox扁平&lt;input type=checkbox style=&quot;position: absolute; clip:rect(5px 15px 15px 5px)&quot; mce_style=&quot;position: absolute; clip:rect(5px 15px 15px 5px)&quot;&gt;&lt;br&gt;# 获取选中内容document.selection.createRange().duplicate().text# 自动完成功能&lt;input type=text autocomplete=on&gt;打开该功能 &lt;input type=text autocomplete=off&gt;关闭该功能 # 窗口最大化&lt;body onload=&quot;window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)&quot;&gt;# 无关闭按钮IEwindow.open(&quot;aa.htm&quot;, &quot;meizz&quot;, &quot;fullscreen=7&quot;);# 统一编码/解码alert(decodeURIComponent(encodeURIComponent(&quot;http://你好.com?as= hehe&quot;)))encodeURIComponent对&quot;:&quot;、&quot;/&quot;、&quot;;&quot; 和 &quot;?&quot;也编码# 表格行指示&lt;tr onmouseover=&quot;this.bgColor='#f0f0f0'&quot; onmouseout=&quot;this.bgColor='#ffffff'&quot;&gt; </textarea>

 

 

 

http://www.blogguy.cn/show-43-1.html

 

原创粉丝点击