我有三个左边,中间和右边的课程,我想交换他们的位置并在他们去新的位置时申请新的课程。但由于某些原因,它不工作 这是我的脚本:为什么jquery中的click事件不适用于我的新元素?
$(function() {
$(".left").css("left","50px");
$(".center").css("left","300px");
$(".center").css("width","300px");
$(".center").css("height","300px");
$(".center").css("top","25px");
$(".right").css("left","650px");
$(".right").click(function(){
$(".left").animate({
left: '650px'
}, 1000, function() {
});
$(".center").animate({
left: '50px',
width: '200px',
top: '75px',
height: '200px'
}, 1000, function() {
});
$(".right").animate({
left: '300px',
width: '300px',
height: '300px',
top: '25px'
}, 1000, function() {
});
$(".bule").removeClass("left right center");
$(".second").addClass("left");
$(".third").addClass("center");
$(".first").addClass("right");
$(".bule").removeClass("first second third");
$(".left").addClass("first");
$(".center").addClass("second");
$(".right").addClass("third");
});
});
Here是一个工作的例子。
您应该减少重复使用的selet的数量以保持可读性和性能。 ''(“。”).css(“width”,“300px”).css(“height”,“300px”);''甚至更好'$(“。center”).css({width:“ 300px“,height:”300px“});'例如。 – Stefan 2013-02-08 13:58:13
@Stefan +1 - 总是一个好主意。 – 2013-02-08 14:05:35