$() 函数是 document.getElementById() 的一个简写形式。
Html代码
1.<%@ page language="java" contentType="text/html; charset=UTF-8"
2. pageEncoding="UTF-8"%>
3.<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4.<html>
5.<head>
6.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7.<script src="js/prototype.js"></script>
8.<title>test</title>
9.</head>
10.<body>
11.
12.<script type="text/javascript" language="javascript">
13.function a() {
14. var div = $('mydiv');
15. var username = $('username');
16. alert(div.innerText + " - " + div.innerHTML + " - " + username.value);
17.}
18.</script>
19.
20.<form action="">
21. <input type="button" οnclick="a()" value="my button"/>
22. <div id="mydiv"><font size="8">初始化内容</font></div>
23. <input type="text" id="username" />
24.</form>
25.
26.</body>
27.</html>