A complete collection of Javascript tips_JavaScript
Event source object
event.srcElement.tagName
event.srcElement.type
Capture release
event.srcElement.setCapture();
event.srcElement.releaseCapture();
Event key
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
Event return value
event.returnValue
Mouse position
event. x
event.y
Form active element
document.activeElement
Bind event
document.captureEvents(Event.KEYDOWN);
Access form element
document. all("txt").focus();
document.all("txt").select();
Form command
document.execCommand
Form COOKIE
document. cookie
Menu event
document.oncontextmenu
Create element
document.createElement("SPAN");
Get element based on mouse:
document.elementFromPoint(event.x,event. y).tagName=="TD
document.elementFromPoint(event.x,event.y).appendChild(ms)
Form pictures
document.images[index]
Form event binding Define
document.onmousedown=scrollwindow;
Element
document.Form.elements[index]
Object binding event
document.all.xxx.detachEvent('onclick',a) ;
Number of plug-ins
navigator.plugins
Get variable type
typeof($js_libpath) == "undefined"
Drop-down box
Drop-down box.options[index]
Drop-down Box.options.length
Find object
document.getElementsByName("r1");
document.getElementById(id);
Timing
timer=setInterval('scrollwindow()',delay );
clearInterval(timer);
UNCODE encoding
escape(),unescape
Parent object
obj.parentElement(dhtml)
obj.parentNode(dom)
Exchange Table rows
TableID.moveRow(2,1)
Replace CSS
document.all.csss.href = "a.css";
Display side by side
display:inline
Hide focus
hidefocus=true
Wrap line according to width
style="word-break:break-all"
Auto refresh
Simple email
Quick Go to location
obj.scrollIntoView(true)
Anchors
anchors
Web page passing parameters
location.search();
Editable
obj.contenteditable=true
Execute menu command
obj.execCommand
Double-byte characters
/[ ^x00-xff]/
Chinese characters
/[u4e00-u9fa5]/
Let the English string automatically wrap when it exceeds the width of the table
word-wrap: break-word; word-break: break-all ;
Transparent background
Get style content
obj.style.cssText
HTML Tag
document.documentElement.innerHTML
The first style tag
document.styleSheets[0]
The first style in the style tag
document.styleSheets[0].rules[0 ]
Prevent the page from being reset to the top of the page when clicking on an empty link.
word
Previous web page source
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
Release memory
CollectGarbage();
Disable right click
document.oncontextmenu = function() { return false;}
Disable saving
Disable selection
Address bar icon
favicon.ico The name is preferably the same 16*16 colors and placed in the root directory of the virtual directory
Favorite bar icon
View source code
Turn off input method
Automatically select all
< input type=text name=text1 value="123" onfocus="this.select()">
ENTER key can move the cursor to the next input box
Default value of text box
title newline
obj.title = "123 sdfs "
Get the microsecond represented by the time
var n1 = new Date("2004-10-10".replace(/-/g, "/")).getTime()
Whether the window Close
win.closed
checkbox flat
Get selected content
document.selection.createRange().duplicate().text
Autocomplete function
Turn on this function
Maximize window
No close button IE
window.open("aa.htm", "meizz", "fullscreen=7");
Uniform encoding/decoding
alert(decodeURIComponent(encodeURIComponent( "http://hello.com?as= hehe")))
encodeURIComponent also encodes ":", "/", ";" and "?"
Table row instructions
< tr onmouseover="this.bgColor='#f0f0f0'" onmouseout="this.bgColor='#ffffff'">
//Various sizes
s = "rnThe width of the visible area of the web page:" document.body.clientWidth;
s = "rnThe height of the visible area of the web page: " document.body.offsetWeight
" (including the width of the edge)"; s = "rnWeb page Visible area height: " document.body.offsetHeight
" (including the width of the edge)"; s = "rn Full text width of the web page: " document.body .scrollWidth;
s = "rnThe full text height of the web page:" document.body.scrollHeight;
s = "rnThe height of the web page being scrolled:" document .body.scrollTop;
s = "rnThe left side of the web page being scrolled:" document.body.scrollLeft;
s = "rnThe main text of the web page:" window.screenTop;
s = "rnThe left side of the text of the web page:" window.screenLeft;
s = "rnThe high screen resolution:" window. screen.height;
s = "rnScreen resolution width:" window.screen.width;
s = "rnScreen available work area height:" window.screen.availHeight;
s = "rnScreen available workspace width:" window.screen.availWidth;
"return event.keyCode>=48&&event .keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false)"
onpaste="return !clipboardData.getData('text' ).match(/D/)" ondragenter="return false">
"window.external.ImportExportFavorites(true,'http://localhost');">
"window.external.ImportExportFavorites(false,'http://localhost');">
"window.external.ShowBrowserUI('OrganizeFavorites', null)">
"window.external.ShowBrowserUI('LanguageDialog', null)">
"window.external.AddFavorite(' http://www.google.com/', 'google')">
"window. external.addChannel('http://www.google.com/')">
"window .external.showBrowserUI('PrivacySettings',null)">
//No caching
"pragma" CONTENT="no-cache">
"Cache -Control" CONTENT="no-cache, must-revalidate">
"expires" CONTENT=" 0">
//Regular matching
Regular expression matching Chinese characters: [u4e00-u9fa5]
Matching double-byte characters (including Chinese characters): [^x00-xff]
Regular expression matching blank lines: n[ s| ]*r
Regular expression matching HTML tags: /<(.*)>.*1>|<(.*) />/
Matching leading and trailing spaces Regular expression: (^s*)|(s*$) (trim function like vbscript)
Regular expression matching email addresses: w ([- .]w )*@w ([-.] w )*.w ([-.]w )*
Regular expression matching URL: http://([w-] .) [w-] (/[w- ./? %&=]*)?
The following is an example:
Use regular expressions to limit the input content of the text box in the web form:
Use regular expressions to limit only Chinese input: onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace (/[^u4E00-u9FA5]/g,''))"
1. Use regular expressions to limit the input of only full-width characters: onkeyup="value=value.replace(/[^ uFF00-uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,' '))"
2. Use regular expressions to limit input to numbers: onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste ="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"
3. Use regular expressions to limit Only numbers and English can be entered: onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData ('text').replace(/[^d]/g,''))"
//Eliminate image toolbar
"mypicture.jpg" HEIGHT=" 100px" WIDTH="100px" GALLERYIMG="false">
or
"imagetoolbar" content="no">
//Close without prompt
function Close()
{
var ua=navigator.userAgent
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 = '';
document.body.insertAdjacentHTML("beforeEnd", str);
document.all.noTipClose.Click();
}
else
{
window.opener =null;
window.close();
}
}
else
{
window.close()
}
}
//取得控件得绝对位置(1)
//获得控件的绝对位置(2)
oRect = obj.getBoundingClientRect();
oRect.left
oRect.
//最小化,最大化,关闭
//光标停在文字最后
"123" onfocus="cc()">
//页面进入和退出的特效
进入页面"Page-Enter" content="revealTrans(duration=x, transition=y)">
推出页面"Page-Exit" content="revealTrans(duration=x, transition=y)">
这个是页面被载入和调出时的一些特效。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
//网页是否被检索
"ROBOTS" content="Attribute value">
The attribute values are as follows:
The attribute value is "all": The files will be retrieved, and the links on the page can be queried;
The attribute value is "none": The files will not be retrieved, and the links on the page will not be queried;
The attribute value is "index": The file will be retrieved;
The attribute value is "follow": The link on the query page;
The attribute value is "noindex": The file is not retrieved, but can be queried for links;
The attribute value is "nofollow":
//Print page break
"page-break-after:always" >page1
"page-break-after:always">page2
//Set up printing
"factory.printing.PageSetup()">
"factory.printing.Preview()">
"打印本页" onclick="factory.printing.Print(false)">
"页面设置" onclick="factory.printing.PageSetup()">
"打印预览" onclick="factory.printing.Preview()">
"http://www.meadroid.com/scriptx/docs/printdoc.htm?static" target=_blank>具体使用手册,更多信息,点这里
//自带的打印预览
WebBrowser.ExecWB(1,1) Open
Web.ExecWB(2,1) Close all current IE windows and open a new window
Web.ExecWB(4,1) Save Web page
Web.ExecWB(6,1) Print
Web.ExecWB(7,1) Print preview
Web.ExecWB(8,1) Print page settings
Web.ExecWB(10,1 ) View page properties
Web.ExecWB(15,1) It seems to be revoked and needs to be confirmed
Web.ExecWB(17,1) Select all
Web.ExecWB(22,1) Refresh
Web .ExecWB(45,1) Close the form without prompting
//Remove the header and footer when printing
"button" value="Calculate content width" onClick="test(txt)" >
//Modeless prompt box
function
modelessAlert(Msg){ window.showModelessDialog("javascript:alert(""
escape(Msg)
"");window.close();" ,"","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;"); }
//Block key
"Content-Type" content="text/html; charset=gb2312">
Shield right mouse button, Ctrl N, Shift F10, Alt F4, F11, F5 refresh, backspace key
//Shield printing
//To move the layer, drag
) onmousemove=MouseMove() onmouseup=MouseUp()>meizz "myp" //文档状态改变
1.this
src=
"logo.gif" ondrag="doDrag ();"
onmouseover=
"this.style.cursor='hand'"
style=
"position:absolute;left=100;top=100;"
onmousedown= "doMouseDown();"> "#" onclick="return false">wlecome< ;/h1>
<script> <br><span style="COLOR: #0000ff">var</span> doc=window.frames[<span style="COLOR: #ff00ff">"f"</span>].document; <br><span style="COLOR: #0000ff">function</span> s(){ <br> <span style="COLOR: #0000ff">if</span> (doc.readyState==<span style="COLOR: #ff00ff">"complete"</span>){ <br> document.all.f.style.height=doc.body.scrollHeight <br> document.all.f.style.width=doc.body.scrollWidth <br> } <br>} <br>doc.onreadystatechange=s <br></script>
//刷新后不变的文本框
"save" CONTENT="history">
//访问剪贴板
(1)拖拽访问
event.dataTransfer.setData("URL", oImage.src);
sImageURL = event.dataTransfer.getData("URL")
(2)普通访问
window.clipboardData.setData("Text",oSource.innerText);
window.clipboardData.getData("Text");
//操作COOKIE
function SetCookie(sName, sValue)
{
document.cookie = sName "=" escape(sValue) "; ";
}
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i )
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
}
function DelCookie(sName)
{
document.cookie = sName "=" escape(sValue) "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
//setTimeout增加参数
<script> <br><span style="COLOR: #0000ff">var</span> _st = window.setTimeout; <br>window.setTimeout = <span style="COLOR: #0000ff">function</span>(fRef, mDelay) { <br> <span style="COLOR: #0000ff">if</span>(typeof fRef == '<span style="COLOR: #0000ff">function</span>'){ <br> <span style="COLOR: #0000ff">var</span> argu = <span style="COLOR: #ff0000">Array</span>.prototype.slice.call(arguments,2); <br> <span style="COLOR: #0000ff">var</span> f = (<span style="COLOR: #0000ff">function</span>(){ fRef.apply(<span style="COLOR: #0000ff">null</span>, argu); }); <br> <span style="COLOR: #0000ff">return</span> _st(f, mDelay); <br> } <br> <span style="COLOR: #0000ff">return</span> _st(fRef,mDelay); <br>} <br><span style="COLOR: #0000ff">function</span> test(x){ <br> alert(x); <br>} <br>window.setTimeout(test,1000,'fason'); <br></script>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).
