prototype中$的使用
时间:2010-10-25 来源:sucre03
最近项目用到了prototype所以来小研究一下,第一讲$的使用,见代码:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>New Web Project</title>
- <script src="prototype.js"></script>
- <script>
- function test1(){
- var d = $('myDiv');
- alert(d.innerHTML);
- }
- function test2(){
- var divs = $('myDiv','myOtherDiv');
- for(i = 0;i<divs.length;i++){
- alert(divs[i].innerHTML);
- }
- }
- </script>
- </head>
- <body>
- <h1>New Web Project Page</h1>
- <div id="myDiv">
- <p>This is a paragraph</p>
- </div>
- <div id="myOtherDiv">
- <p>This is another paragraph</p>
- </div>
- <input type="button" value="test1" onclick="test1();"/>
- <input type="button" value="test2" onclick="test2();"/>
- </body>
- </html>
运行界面
点test1时会出现1对话框,点test2会出现1、2对话框,prototype中的$就相当于js中的document.getElementById,好了快去试试,一起学习进步。
相关阅读 更多 +