1. Disable the right-click menu for the page
$ (document). Ready (function () { $ (document). Bind ("contextmenu", Function (e) { returnfalse; }) })
2. New Window open page
$ (document). The hyperlink for Ready (function() {// Example 1:href= "/http" will open in a new window $ (' A [href^= "http://"] '). attr ("target", "_blank"); // example 2:rel= "external" hyperlink will open in a new window $ (' a[rel$= ' external "]). Click (function() {this. target =" _blank "; }) })
3. Determine browser type
$(function(){ varBrow =$.browser; //Firefox 2 and above if(Brow.mozilla && brow.version>= "1.8") {alert ("Firefox"); } //Safari if(Brow.safari) {alert ("Safari"); } //Chrome if(brow.chrome) {alert ("Chrome"); } //Opera if(Brow.opera) {alert ("Opera"); } //IE6 and below if(Brow.msie && brow.version <= 6) {alert ("<=ie6"); } //above IE6 if(Brow.msie && brow.version > 6) {alert (">ie6"); } })
After the JQ 1.3 version, the official recommendation is to use $.support instead of $.browser
Note: The above method does not apply to versions 1.9 and above
4. Input box text get and lose focus
$(function(){ $(' Input.text1 '). Val (' Enter your search text here '); Textfill ($ (' Input.text1 ')); }) functionTextfill (input) {varOriginalValue =Input.val (); Input.focus (function(){ if($.trim (Input.val ()) = = OriginalValue) {//If the input box is the original content, click Empty value to make it easy to enterInput.val (' '); }}). blur (function(){ if($.trim (Input.val ()) = = ") {//If the input box content is empty, that is, the previous click did not enter, the mouse left to restore the original contentInput.val (OriginalValue); } }) }
5. Return to head slide animation
function (speed) { var targetoffset = $ (this). Offset (). Top; $ (' html,body '). Stop (). Animate ({scrolltop:targetoffset},speed); return This ; } $ ("#goHeader"). Click (function () { $ ("body"). ScrollTo; return FAL
6. Get the mouse position
$ (function() { $ (document). MouseMove (function(e) { $ ("#XY"). HTML ("X: "+ e.pagex+" | Y: "+ E.pagey);}) })
jquery Tips (i)