JavaScript Testing Prototype
Testing JavaScript framework library - Prototype
References Prototype
To test JavaScript library, you need to reference it in a Web page.
To refer to a library, use the <script> tag, whose src attribute set to the URL library:
References Prototype
<html>
<head>
<script
src="http://apps.bdimg.com/libs/prototype/1.7.1.0/prototype.js">
</script>
</head>
<body>
</body>
</html>
Prototype Description
Prototype provides functions enable HTML DOM programming easier.
Similar to jQuery, Prototype also has its own $ () function.
$ () Function accepts id value HTML DOM element (or a DOM element), and will add new features to the DOM object.
Different with jQuery, Prototype not to replace window.onload () is ready () method. Instead, Prototype will add an extension to the browser and HTML DOM.
In JavaScript, you can assign a function to handle window load event:
JavaScript method:
{
var obj=document.getElementById("h01");
obj.innerHTML="Hello Prototype";
}
onload=myFunction;
Equivalent Prototype is different:
Prototype mode:
{
$("h01").insert("Hello Prototype!");
}
Event.observe(window,"load",myFunction);
Event.observe () accepts three parameters:
- You want to deal with the HTML DOM or BOM (Browser Object Model) objects
- Event you want to handle
- The function you want to call
Testing Prototype
Please try the following example:
Example
<html>
<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>
try it"
Please try again at this example:
Example
<html>
<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>
Test >>
As you can see in the example above, the same as jQuery, Prototype allows the chain syntax.
Link (Chaining) is a method of performing multiple tasks on the same subject convenient method.