博文

目前显示的是标签为“JavaScript”的博文

javascript Alert and url query

<!DOCTYPE html> <html> <head> <style> .alert {     padding: 20px;     background-color: #f44336;     color: white; } .closebtn {     margin-left: 15px;     color: white;     font-weight: bold;     float: right;     font-size: 22px;     line-height: 20px;     cursor: pointer;     transition: 0.3s; } .closebtn:hover {     color: black; } </style> </head> <body> <h2>Alert Messages</h2> <p>Click on the "x" symbol to close the alert message.</p> <div class="alert">   <span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span>   <strong>Danger!</strong> Indicates a dangerous or potentially negative action. </div> </body> </html...

javascript-object-prototype

图片
From : https://www.byvoid.com/blog/javascript-object-prototype function Foo () { } var foo = new Foo (); var obj = new Object ();

defer vs async in script

图片
The blue line means loading times. Ref: segmentfault. com/ q / 1010000000640869

Underscore.js Backbone.js

Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It’s the answer to the question: “If I sit down in front of a blank HTML page, and want to start being productive immediately, what do I need?” … and the tie to go along with jQuery 's tux and Backbone 's suspenders.  http://underscorejs.org/ Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.  http://backbonejs.org http://www.quora.com/What-JavaScript-framework-does-Flow-use-for-its-web-frontend - jQuery for DOM manipulation - Underscore.js for awesome, rock solid, and progressive utility - A heavily modified Backbone.js for the model...

array in javascript

Array 1. sort & reverse e.g. : var a2=[10,2,3,1,7]; a2.reverse();// 7,1,3,2,10 a2.sort();//1,10,2,3,7 function compare(value1,value2){   if(value1<value2){return -1;}   else if(value1>value2){return 1;}   else{return 0;} } a2.sort(compare);// 1,2,3,7,10 function getType(obj){   let type= typeof obj;   if(type!=='object'){return type;}   return Object.prototype.toString.call(obj).replace(/^\[object (\S+)\]$/,'$1');    // [object Number] } var x = 15 * 5; getType(x); // Number

Unicode 5.0 and javascript ☯ ☯ ࿊ ࿊䷀

易经六十四卦符号 YI JING H exagram S ymbol ( &#19904 ) ( &#19905 ) ( &#19906 ) ( &#19907 ) ( &#19908 ) ( &#19909 ) ( &#19910 ) ( &#19911 ) ( &#19912 ) ( &#19913 ) ( &#19914 ) ( &#19915 ) ( &#19916 ) ( &#19917 ) ( &#19918 ) ( &#19919 ) ( &#19920 ) ( &#19921 ) ( &#19922 ) ( &#19923 ) ( &#19924 ) ( &#19925 ) ( &#19926 ) ( &#19927 ) ( &#19928 ) ( &#19929 ) ( &#19930 ) ( &#19931 ) ( &#19932 ) ( &#19933 ) ( &#19934 ) ( &#19935 ) ( &#19936 ) ( &#19937 ) ( &#19938 ) ( &#19939 ) ( &#19940 ) ( &#19941 ) ( &#19942 ) ( &#19943 ) ( &#19944 ) ( &#19945 ) ( &#19946 ) ( &#19947 ) ( &#19948 ) ( &#19949 ) ( &#19950 ) ( &#19951 ) ( &#19952 ) ( &#19953 ) ( &#19954 ) ( &#19955 ) ( &#19956 ) ( &#19957 ) ( &#19958 ) ( &#19959 ) ( &#19960 ) ( &#19961 ) ( &#19962 ) ( &#19...

Cross-window messaging with postMessage

Ref: http://javascript.info/tutorial/cross-window-messaging-with-postmessage#example Cross-window messaging API is supported by all modern browsers including IE8. It allows windows/frames from multiple domains to communicate with each other. To send a message to another window referenced by win , the postMessage method is used. Syntax is postMessage(data, targetDomain) , where: data The message. Accordin to the specification, it could be any object. But as of now, only strings are supported in major browsers. targetDomain Limit receiving iframe by given domain. Can contain ‘*’ which doesn’t put any restrictions. Usually, the domain of iframe is known, so it is recommended to pass it as the targetDomain argument for better security. Example Let’s see how it works from the sending side. 01 < iframe src = "http://a.JavaScript.info/files/tutorial/window/receive.html" id = "iframe" style = "height:60px" ></ iframe > 02 ...

review onkeypress in Html

only number in input 1. <input onkeypress ="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" style=" ime-mode:Disabled ">" The ime-mode CSS property controls the state of the input method editor for text fields.   Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/ime-mode 2. <input type=text onkeypress=" return test();" style=" ime-mode:Disabled " > function test(){    return /[\d]/.test(String.fromCharCode(event.keyCode)); } 3<input type=text onkeypress="test()" style=" ime-mode:Disabled " > function test(){   //if ( isNaN (this.value)){    window.event.returnValue =false;   }    } other: <input name="username" type="text" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"> only letter, number, &, = and @ <input name="username" type="text" onkeyup="value=value.replace(/[^\w=@&]|_/ig,''...

review: Array.sort - javascript

Example 1: <html> <body> <script type="text/javascript"> Array.prototype.sort02=function(a,b){   return -1; } var arr = new Array(6) arr[0] = {"A":0}; arr[1] = {"A":1}; arr[2] = {"A":2}; arr[3] = {"A":3}; arr[4] = {"A":4}; arr[5] = {"A":5}; arr.sort(function(a,b){ // document.write("a.A"+a.A+"--b.A" + b.A+"<br/>");  return 1; }); document.write("Array.sort:----<br/>"); for (var i in arr){   if(typeof(arr[i])=="object")   document.write("arr["+i+"]:"+arr[i].A+"<br/>"); } arr.sort02(); document.write("Array.sort02:----<br/>"); for (var i in arr){   if(typeof(arr[i])=="object")   document.write("arr["+i+"]:"+arr[i].A+"<br/>"); } </script> </body> Result:-------------- Array.sort:---- arr[0]:5 ar...

private variables in javascript

 (function(window){      //private variables     var name = "test";         var pieAGSI = function(){};     // get variable     pieAGSI.prototype.getName = function(){         return name;     };         // update variable     pieAGSI.prototype.setName = function(str){         name = str;     };         window.pieAGSI = pieAGSI;     })(window); // test var test = new pieAGSI(); document.write('<br>test.getName(): ' + test.getName()+"<br>");

Proxy Pattern & AOP in JavaScript

Proxy Pattern & AOP in JavaScript To implement a proxy pattern in JavaScript, enabling the basics of aspect-oriented Programming(AOP) function test(){   console.log(this,"It is a test."); } (function(){   var toProxy = test;   test = function(){     console.log( this, "proxied" ,arguments );     return toProxy.apply( this );   }; } )(); test(); //Window test.html proxied [ ] //Window test.html It is a test.