本文實例講述了JS創建對象的寫法。分享給大家供大家參考,具體如下:
寫法1:
<script>var database = function () {  function add(){    console.info("add");  }  function queryAll(){    console.info("queryAll");  }  /**  帶參數  */  function delById(id){    console.info("delById:" +id);  }  return {    add:add,    queryAll:queryAll,    delById:delById  }}();database.add();database.delById(34);console.info(database);</script>URL HASH:
<script src="js/jquery-2.1.4.min.js"></script><script>  function route() {    var page = window.location.hash;    console.info(page);  }  $(function() {    $(window).bind("hashchange", route);  })</script><a href="#1">1</a><a href="#2">2</a>我們通過綁定hashchange事件,當點擊連接時可以實現使用ajax實現無刷新跳轉。
希望本文所述對大家JavaScript程序設計有所幫助。
新聞熱點
疑難解答