HomeWeb Front-endJS TutorialA 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

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


//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;


//Filter numbers

"return event.keyCode>=48&&event .keyCode onpaste=

"return !clipboardData.getData('text' ).match(/D/)" ondragenter="return false">


//Special Purpose

"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

A complete collection of Javascript tips_JavaScript"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  {
   var str  = '"clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
       str  = '"Command" value="Close">
';
       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.


//最小化,最大化,关闭

"clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> 
"Command" value="Minimize">
 
"clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> 
"Command" value="Maximize">
 
"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"> 
"Command" value="Close">
 
 
 
 


//光标停在文字最后 


"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" style="display:none" viewastext
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
  codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"
>

"factory.printing.PageSetup()">
"factory.printing.Preview()">

<script> <br/><span style="COLOR: #0000ff">function window.onload() <br/>{ <br/>   <span style="COLOR: #008000">// -- advanced features <br/>   factory.printing.SetMarginMeasure(2) <span style="COLOR: #008000">// measure margins in inches <br/>   factory.printing.SetPageRange(<span style="COLOR: #0000ff">false, 1, 3) <span style="COLOR: #008000">// need pages from 1 to 3 <br/>   factory.printing.printer = <span style="COLOR: #ff00ff">"HP DeskJet 870C" <br/>   factory.printing.copies = 2 <br/>   factory.printing.collate = true <br/>   factory.printing.paperSize = <span style="COLOR: #ff00ff">"A4" <br/>   factory.printing.paperSource = <span style="COLOR: #ff00ff">"Manual feed" <br/>   <span style="COLOR: #008000">// -- basic features <br/>   factory.printing.header = <span style="COLOR: #ff00ff">"居左显示&b居中显示&b居右显示页码,第&p页/共&P页" <br/>   factory.printing.footer = <span style="COLOR: #ff00ff">"(自定义页脚)" <br/>   factory.printing.portrait = false <br/>   factory.printing.leftMargin = 0.75 <br/>   factory.printing.topMargin = 1.5 <br/>   factory.printing.rightMargin = 0.75 <br/>   factory.printing.bottomMargin = 1.5 <br/>} <br/><span style="COLOR: #0000ff">function Print(frame) { <br/>  factory.printing.Print(<span style="COLOR: #0000ff">true, frame) <span style="COLOR: #008000">// print with prompt <br/>} <br/></script>
"打印本页" 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

"WebBrowser"

width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">


"Noprint" >






//Remove the header and footer when printing

//Browser verification


 

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=(document.layers && !this.dom)?1:0; 
   this.mac=(this.ver.indexOf('Mac') > -1) ?1:0; 
   this.ope=(navigator.userAgent.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)
{
range = obj .createTextRange(); alert("Content area width: "
range.boundingWidth " "pxrn content area height: " range.boundingHeight
"px" ); }

"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 the right mouse button, Ctrl N, Shift F10, Alt F4, F11, F5 refresh, backspace key


Shield right mouse button, Ctrl N, Shift F10, Alt F4, F11, F5 refresh, backspace key
//Shield printing



//To move the layer, drag



1.this

) onmousemove=MouseMove() onmouseup=MouseUp()>meizz

function MouseDown(obj)

{ Obj=obj; Obj. setCapture();
Obj.l=event.x-Obj.style.pixelLeft;
Obj.t=event.y-Obj.style.pixelTop; }
function MouseMove() {

if
(Obj!=
null
)
{
Obj.style.left = event.x-Obj. l; Obj.style.top = event.y-Obj.t; }
}
function MouseUp() {
if
(Obj!=
null
)
{
Obj.releaseCapture(); Obj=null
;
} } 2.

"myp"
src=
"logo.gif" ondrag="doDrag ();"
onmouseover=
"this.style.cursor='hand'"
style=
"position:absolute;left=100;top=100;"
onmousedown= "doMouseDown();"> "#" onclick="return false">

wlecome< ;/h1>

"text/javascript"
> var orgMouseX;
var
orgMouseY; var orgObjX; function
doDrag() {
var myObject=document.all.myp;
var x=event.clientX ;
var y=event.clientY;
myObject.style.left=x-(orgMouseX-orgObjX); myObject.style.top=y-(orgMouseY-orgObjY) ;
}
function doMouseDown()
{
orgMouseX=event.clientX; orgMouseY=event.clientY; orgObjX=parseInt( document.all.myp.style.left);
orgObjY=parseInt(document.all.myp.style.top); }







//文档状态改变 

 id="f" name="f" scrolling="no" frameborder=0 marginwidth=0 marginheight=0>
<script> <br/><span style="COLOR: #0000ff">var doc=window.frames[<span style="COLOR: #ff00ff">"f"].document; <br/><span style="COLOR: #0000ff">function s(){ <br/> <span style="COLOR: #0000ff">if (doc.readyState==<span style="COLOR: #ff00ff">"complete"){ <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  {

  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 _st = window.setTimeout; <br/>window.setTimeout = <span style="COLOR: #0000ff">function(fRef, mDelay) { <br/> <span style="COLOR: #0000ff">if(typeof fRef == '<span style="COLOR: #0000ff">function'){ <br/>  <span style="COLOR: #0000ff">var argu = <span style="COLOR: #ff0000">Array.prototype.slice.call(arguments,2); <br/>  <span style="COLOR: #0000ff">var f = (<span style="COLOR: #0000ff">function(){ fRef.apply(<span style="COLOR: #0000ff">null, argu); }); <br/>  <span style="COLOR: #0000ff">return _st(f, mDelay); <br/> } <br/> <span style="COLOR: #0000ff">return _st(fRef,mDelay); <br/>} <br/><span style="COLOR: #0000ff">function test(x){ <br/> alert(x); <br/>} <br/>window.setTimeout(test,1000,'fason'); <br/></script>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Javascript Data Types : Is there any difference between Browser and NodeJs?Javascript Data Types : Is there any difference between Browser and NodeJs?May 14, 2025 am 12:15 AM

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScript Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor