雖然做b/s也有一年半了,但是還沒怎麼認真的去看JQuery,趁自己生病的這幾天,惡補一下JQuery方面的知識,保持學習的態度,內容很簡單,聊以自慰一下>_<。廢話不多說,直接上代碼了。
通過HTML標簽實現控件隱藏:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>按鈕點擊消失文本</title>
<script src="jquery.js"></script>
<script type="text/javascript" language="javascript">
/*獲取文本對象*/
$(document).ready(function () {
/*從文本對象中獲取到button標簽的點擊事件*/
$("button").click(function () {
/*獲取到p標簽的點擊事件*/
$("p").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph</p>
<p>This is a another paragraph</p>
<button type="button">Click me</button>
<input type="button" value="Click me" />
</body>
</html>
通過控件ID實現對象隱藏:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>通過ID隱藏控件</title>
<script src="jquery.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("button").click(function () {
$("#test").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph</p>
<p id="test">This is another paragraph</p>
<button type="button">隱藏控件id為test的p標簽</button>
</body>
</html>