为什么这个jQuery不起作用

Why won't this jQuery work?

本文关键字:不起作用 jQuery 为什么      更新时间:2023-09-26
<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>

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

$(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');
        }
);