jQuery 库 - 特性
jQuery 是一个 JavaScript 函数库。
jQuery 库包含以下特性:
- HTML 元素选取
- HTML 元素操作
- CSS 操作
- HTML 事件函数
- JavaScript 特效和动画
- HTML DOM 遍历和修改
- AJAX
- Utilities
向您的页面添加 jQuery 库
jQuery 库位于一个 JavaScript 文件中,其中包含了所有的 jQuery 函数。
可以通过下面的标记把 jQuery 添加到网页中:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
请注意,<script> 标签应该位于页面的 <head> 部分。
代码示例:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<button type="button">1</button>
<button type="button">2</button>
</body>
</html>
点击按钮1时: 按钮1隐藏,但是按钮2没有隐藏,说明this代表执行的对象。
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("button").hide();
});
});
</script>
</head>
<body>
<button type="button">1</button>
<button type="button">2</button>
</body>
</html>
点击按钮1时,两个按钮都会消失,因为作用对象为所有button。
$("button")和type="button"没有任何关系。