closure-library - Revision 9: /trunk/closure/goog/demos
スクリプトをheadタグ内に書くとエラーが出る。
エラーが出る場合
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Google Closure Tools Sample</title> <script src="closure-library-read-only/closure/goog/base.js"></script> <script type="text/javascript"> //ライブラリの読み込み goog.require("goog.events"); goog.require('goog.dom'); //イベントリスナーの追加 goog.events.listen(document.getElementById("btn"), "click", sayHi); function sayHi() { var newHeader = goog.dom.createDom('h1', {'style': 'background-color:#EEE'}, 'Hello world!'); goog.dom.appendChild(document.body, newHeader); } </script> </head> <body> <input type="button" id="btn" value="push" /> </body> </html>
エラーなしに実行できる場合
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Google Closure Tools Sample</title> <script src="closure-library-read-only/closure/goog/base.js"></script> <script type="text/javascript"> //ライブラリの読み込み goog.require("goog.events"); goog.require('goog.dom'); </script> </head> <body> <input type="button" id="btn" value="push" /> </body> <script> //イベントリスナーの追加 goog.events.listen(document.getElementById("btn"), "click", sayHi); function sayHi() { var newHeader = goog.dom.createDom('h1', {'style': 'background-color:#EEE'}, 'Hello world!'); goog.dom.appendChild(document.body, newHeader); } </script> </html>