發表文章

目前顯示的是有「javascript」標籤的文章

Get URL Parameters using jQuery

Get URL Parameters using jQuery To implement this, I have created a function which returns value of any  parameters  variable. function GetURLParameter(sParam) { var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); if (sParameterName[0] == sParam) { return sParameterName[1]; } } }​ And this is how you can use this function assuming the URL is,  " http://dummy.com/?technology=jquery&blog=jquerybyexample ".  var tech = GetURLParameter('technology'); var blog = GetURLParameter('blog'); So in above code variable " tech " will have " jquery " as value and " blog " variable's will be " jquerybyexample ". Source from: http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery...

Prevent Default Behaviour of Hashed Anchor Tag with jQuery

Prevent Default Behaviour of Hashed Anchor Tag with jQuery Way back in the day, I use to always set up my event triggering anchor tags a certain way to prevent their default behaviour of having to click-through to a URL or named anchor: $( 'a[href="#"]' ).click( function(e) { e.preventDefault(); } );

[Javascript] Preview an image after browse the file

Preview an image after browse the file Javascript in Page function readURL ( input ) { if ( input . files && input . files [ 0 ]) { var reader = new FileReader (); reader . onload = function ( e ) { $ ( '#image' ). attr ( 'src' , e . target . result ); } reader . readAsDataURL ( input . files [ 0 ]); } } $ ( "#upload" ). change ( function (){ readURL ( this ); });   HTML in Page: <form id = "form1" runat = "server" > <input type = 'file' id = " upload " /> <img id = " image " src = "#" alt = "your image" /> </form>

[Javascript] Check email if it is valid

Use Javascript to check email if it is valid function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00...

[Jquery] To check if checkbox is checked

Simple code to know if checkbox is checked if( $('#CHECKBOX-ID').is(':checked') ){       // checkbox is checked }else{      // checkbos is not checked }

audio.js

Javascript Audio Player <audio.js> audio.js 00:00 / 04:07 audio.js is a drop-in javascript library that allows HTML5’s <audio> tag to be used anywhere. It uses native <audio> where available and an invisible flash player to emulate <audio> for other browsers. It provides a consistent html player UI to all browsers which can be styled used standard css. Download  audio.js Installation Put  audio.js ,  player-graphics.gif  &  audiojs.swf  in the same folder. Include the  audio.js  file: <script src="/audiojs/audio.min.js"></script> Initialise audio.js: <script> audiojs.events.ready(function() { var as = audiojs.createAll(); }); </script> Then you can use  <audio>  wherever you like in your HTML: <audio src="/mp3/juicy.mp3" preload="auto" /> Examples A series of API tests & examples for using and extending audio.js ...

Minify

圖片
Minify - Combines, minifies, and caches JavaScript and CSS files on demand to speed up page loads.   Minify is a PHP5 app that helps you follow several of Yahoo!'s Rules for High Performance Web Sites.  It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers. Minify in Use Before After The stats above are from a  brief walkthrough  which shows how easy it is to set up Minify on an existing site. It eliminated 5 HTTP requests and reduced JS/CSS bandwidth by 70%. The design is somewhat similar to Yahoo's  Combo Handler Service , except that Minify can combine  any  local JS/CSS files you need for your page. Minify integrated into other Projects/Plugins WordPress:  WP-Minify WordPress:  W3 Total Cache Zend Framework:  View helpers for links/scripts Yii:  minscript Extension Features Combines an...