<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var i=0;
$("#but1").click(function(){
i++;
if (i%2==0) {
$("#p1").show(1000);
} else {
$("#p1").hide(1000);
}
});
//效果同上
$("#but2").click(function(){
$(".p2").toggle(1000);
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p id="p1">This is a paragraph.</p>
<p class="p2">This is another paragraph.</p>
<button type="button" id="but1">隐藏/显示p1</button>
<button type="button" id="but2">隐藏/显示p2</button>
</body>
</html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var i=0;
$("#but1").click(function(){
i++;
if (i%2==0) {
$("#p1").show(1000);
} else {
$("#p1").hide(1000);
}
});
//效果同上
$("#but2").click(function(){
$(".p2").toggle(1000);
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p id="p1">This is a paragraph.</p>
<p class="p2">This is another paragraph.</p>
<button type="button" id="but1">隐藏/显示p1</button>
<button type="button" id="but2">隐藏/显示p2</button>
</body>
</html>