引用 Prototype
如需測試 JavaScript 函式庫,您需要在網頁中引用它。
為了引用某個函式庫,請使用<script> 標籤,其src 屬性設定為庫的網址:
<!DOCTYPE html>
<html>
<head>
<scriptsrc="http://apps.bdimg.com/libs/prototype/1.7.1.0/prototype.js"></script>
</head>
<body>
</body>
</html>
function myFunction(){
var obj=document.getElementById("h01");
obj.innerHTML="Hello Prototype";
}
onload=myFunction;
function myFunction(){
$("h01 ").insert("Hello Prototype!");
}
Event.observe(window,"load",myFunction);
實例比較:##
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <script src="http://apps.bdimg.com/libs/prototype/1.7.1.0/prototype.js"></script> <script> function myFunction(){ $("h01").insert("Hello Prototype!"); } Event.observe(window,"load",myFunction); </script> </head> <body> <h1 id="h01"></h1> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <script src="http://apps.bdimg.com/libs/prototype/1.7.1.0/prototype.js"></script> <script> function myFunction(){ $("h01").writeAttribute("style","color:red").insert("Hello Prototype!"); } Event.observe(window,"load",myFunction); </script> </head> <body> <h1 id="h01"></h1> </body> </html>