<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function (){
$("#kep").click(function (){
$("#pic").fadeOut('slow', function (){
$("#pic").html('<img src="y.jpg">', function (){
$("#pic").fadeIn('fast');
});
});
});
});
</script>
<div id="pic">
<center><img id="kep" src="x.jpg"></center>
</div>
这很烦人,我不知道为什么我这么难以失败。 &GT;。&LT;
答案 0 :(得分:3)
$(document).ready(function() {
$("#kep").click(function() {
$("#pic").fadeOut('slow', function() {
$(this) // point to #pic
.html('<img src="y.jpg">ddd') // append image to #pic
.fadeIn('fast'); // make fadeIn #pic
});
});
});
代码错误:
$("#pic").html('<img src="y.jpg">',
function (){
// within this callback you are trying to make fadeIn()
// which is not possible
// this callback is to process the innerHTML of
// #pic, not the #pic itself
$("#pic").fadeIn('fast');
}
);