Home >Web Front-end >JS Tutorial >JavaScript Strengthening Tutorial—Prototype

JavaScript Strengthening Tutorial—Prototype

巴扎黑
巴扎黑Original
2016-12-05 11:31:551041browse

This article is the official HTML5 training tutorial of H5EDU organization. It mainly introduces: JavaScript enhancement tutorial - Prototype

Quoting Prototype
If you need to test the JavaScript library, you need to reference it in the web page.
To reference a library, use the <script> tag with its src attribute set to the URL of the library: <br>Reference Prototype <br><!DOCTYPE html> <br><html> <br><head> <br><script <br/>src ="http://apps.bdimg.com/libs/pro ... gt%3B <br/></script>





Prototype Description
Prototype provides functions that make HTML DOM programming easier.
Similar to jQuery, Prototype also has its own $() function.
$() function accepts the id value of the HTML DOM element (or DOM element), and Will add new functionality to the DOM object.
Unlike jQuery, Prototype does not have a ready() method that replaces window.onload(). Instead, Prototype adds extensions to the browser and HTML DOM.
In JavaScript, you can. Assign a function to handle the window load event:
JavaScript way:
function myFunction()
{
var obj=document.getElementById("h01");
obj.innerHTML="Hello Prototype";
}
onload=myFunction;
The equivalent Prototype is different:
Prototype method:
function myFunction()
{
$("h01").insert("Hello Prototype!");
}
Event.observe(window,"load", myFunction);
Event.observe() accepts three parameters:
The HTML DOM or BOM (Browser Object Model) object you want to handle
The event you want to handle
The function you want to call
Test Prototype
Please try the following This example:
Example