<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>e1.html</title>
<style type="text/css">
.s1{
width:100px;
height:100px;
background-color:red;
}
#d2{
width:100px;
heigth:100px;
background-color:green;
}
</style>
<script type="text/javascript" src="js/jquery-1.4.3.js"></script>
<script type="text/javascript">
function click(){
$('#a1').toggle(function(){
$('#d2').show('slow',function(){
//alert('hello');
});
},function(){
$('#d2').hide('slow',function(){
//alert('world');
});
}); }
</script>
</head>
<body style="font-size: 30px;">
<a href="javascript:;" id="a1" class="s1" onclick="click();">如何才能致富</a>
<div id="d2" style="width:200px; height:200px; border:1px solid black; display:none" >好好学习Java</div>
</body>
</html>
这段代码的点击事件 怎么样解决点击隐藏问题啊,每次点击最后总是没办法隐藏不用$(function() {});方法恳求高手帮忙!!
<html>
<head>
<title>e1.html</title>
<style type="text/css">
.s1{
width:100px;
height:100px;
background-color:red;
}
#d2{
width:100px;
heigth:100px;
background-color:green;
}
</style>
<script type="text/javascript" src="js/jquery-1.4.3.js"></script>
<script type="text/javascript">
function click(){
$('#a1').toggle(function(){
$('#d2').show('slow',function(){
//alert('hello');
});
},function(){
$('#d2').hide('slow',function(){
//alert('world');
});
}); }
</script>
</head>
<body style="font-size: 30px;">
<a href="javascript:;" id="a1" class="s1" onclick="click();">如何才能致富</a>
<div id="d2" style="width:200px; height:200px; border:1px solid black; display:none" >好好学习Java</div>
</body>
</html>
这段代码的点击事件 怎么样解决点击隐藏问题啊,每次点击最后总是没办法隐藏不用$(function() {});方法恳求高手帮忙!!
解决方案 »
- 关于severlet版本问题
- 现在是学android开发好呢?还是web开发好,我是新手
- STRUTS2的数据修改问题
- jdbc 连接url中的参数,mysql设置数据库、表的参数是什么意思?
- 各位大侠帮帮小弟,javaScript验证问题,运行后没有显示验证结果,大家帮忙看下是什么问题,谢谢啦
- 为什么连接数MSsql2000据库正确,并且能有正确运行,但仍然 提示错误
- 提取网页标题<title>..</title>的正则表达式怎么写?
- 問一個tomcat路徑問題
- 新手求救啊!在jbuilder2005中怎樣加入commons-fileupload-1.0.jar
- 有高手吗?急,急,急,请快给我解答,谢谢
- 用intelli Idea 11 javax.server包怎么导入?
- 在后台如何实现发送一个http请求,但要求不跳转
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>e1.html</title>
<style type="text/css">
.s1{
width:100px;
height:100px;
background-color:red;
}
#d2{
width:100px;
heigth:100px;
background-color:green;
}
</style>
<script type="text/javascript" src="E:/workzone/ucenter_ff/WebRoot/ucenter/js/jquery-1.6.4.min.js"></script>
<script type="text/javascript">window.onload = function(){
$('#a1').toggle(function(){
$('#d2').show('slow',function(){
//alert('hello');
}); },function(){
$('#d2').hide('slow',function(){
//alert('world');
});
});
}
</script>
</head>
<body style="font-size: 30px;">
<a href="javascript:;" id="a1" class="s1">如何才能致富</a>
<div id="d2" style="width:200px; height:200px; border:1px solid black; display:none" >好好学习Java</div>
</body>
</html>
toggle 就是绑定点击事件的 不需要给a1的点击事件每次都执行toggle所以直接在页面加载完成后 把a1绑定toggle事件就行了
第一次点击时会不显示“好好学习java”,可以把function改成这样就没问题了。function click(){
$('#d2').slideToggle("slow");
}
如果仅仅为了隐藏或显示的效果,用toggle或slideToggle就足够了。