1
<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>

这很烦人,我不知道为什么我这么努力地失败了。>.<

4

1 回答 1

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');
        }
);
于 2012-05-28T17:38:19.170 回答