Home >Web Front-end >JS Tutorial >A complete collection of Javascript tips_JavaScript

A complete collection of Javascript tips_JavaScript

PHP中文网
PHP中文网Original
2016-05-16 19:29:151265browse

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;


//Filter numbers

"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">


//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: /<(.*)>.*|<(.*) />/
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  = '"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)

"javascript"> 
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

//获得控件的绝对位置(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"
 
 
 


//光标停在文字最后 

"javascript">
function cc()
{
 var e = event.srcElement;
 var r =e.createTextRange();
 r.moveStart('character',e.value.length);
 r.collapse(true);
 r.select();
}

"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()">


function window.onload()
{
   // -- advanced features
   factory.printing.SetMarginMeasure(2) // measure margins in inches
   factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3
   factory.printing.printer = "HP DeskJet 870C"
   factory.printing.copies = 2
   factory.printing.collate = true
   factory.printing.paperSize = "A4"
   factory.printing.paperSource = "Manual feed"
   // -- basic features
   factory.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页"
   factory.printing.footer = "(自定义页脚)"
   factory.printing.portrait = false
   factory.printing.leftMargin = 0.75
   factory.printing.topMargin = 1.5
   factory.printing.rightMargin = 0.75
   factory.printing.bottomMargin = 1.5
}
function Print(frame) {
  factory.printing.Print(true, frame) // print with prompt
}

"打印本页" 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



"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">



//To move the layer, drag



1.this

) onmousemove=MouseMove() onmouseup=MouseUp()>meizz 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>








//文档状态改变 

"a.html" id="f" name="f" scrolling="no" frameborder=0 marginwidth=0 marginheight=0>
<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>

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
Previous article:Organizing common special effects codes for web pages_JavaScriptNext article:Organizing common special effects codes for web pages_JavaScript

Related articles

See more