各位看看这个代码中的click事件为什么不执行呢?谢谢

冷月无声 2012-08-03
1.html页面代码

<DOCTYPE!html>
<html>
<head>
<title>
demo 02
</title>
<style type="text/css">
.demo {
text-align:center;
vertical-align:center;
}
img {
width:150px;
height:150px;
}
</style>

</head>
<body>
<div class="demo">
<img src="./images/1.jpg" alt="1"/>
<img src="./images/2.jpg" alt="2"/>
<img src="./images/3.jpg" alt="3"/>
</div>
<script type="text/javascript" src="./jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="./jquery.gallery.js"></script>
<script type="text/javascript" src="./jquery.center.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".demo").css({
height:'200',
width:'500'}).center();
$('img').gallery();
alert($('.hello'))
$("#mygalleryId").click(function(){
var attr=$(this).attr('alt');
alert(attr);
$(this).remove();
$('.demo img[alt=attr]').next(img).gallery();
});
$(window).resize(function(){
$("#mygalleryId").center();
$(".demo").css({
height:'200',
width:'500'}).center();

});

});
</script>
</body>
</html>
2.jquery.gallery.js
(function($){
$.fn.gallery=function(options){
return this.each(function(){
var e=$(this);
var h=e.height();
e.height(128);
e.click(function(){
$('#mygalleryId').remove();

e.clone()
.attr('id','mygalleryId')
.prependTo('body')
.css({
width:'300',
height:'300'
})
.center();

$("img:not(#mygalleryId)").css('visibility','hidden');
});
});
}
})(jQuery)
witcheryne 2012-08-03
动态生成的的用live
dingchao.lonton 2012-08-06
不用live也行,也可以用delegate来实现
pxjianke 2012-08-09
alert($('.hello'))
冷月无声 2015-07-17
   
ocwuyou 2015-08-07
see it
http://www.xuetub.com
Global site tag (gtag.js) - Google Analytics