0

我的 jQuery 代码是:

                num=15;                     
                        $('#share_button_'+num).mouseover(function(){       
                            $('#share_button_'+num).attr("src","img/share-hover.jpg");      
                        });                         
                        $('#share_button_'+num).mouseout(function(){        
                            $('#share_button_'+num).attr("src","img/share-button-en.jpg");      
                        });

                num=30;

                        $('#share_button_'+num).mouseover(function(){                               
                            $('#share_button_'+num).attr("src","img/share-hover.jpg");      
                        });                         
                        $('#share_button_'+num).mouseout(function(){        
                            $('#share_button_'+num).attr("src","img/share-button-en.jpg");      
                        });

我的问题是只有最后一个(可以是 15 或 30)有效。Is 写在 Ajax 成功响应中:

        $.ajax({
        async: true,
        url: "myurl.php",
        type: "POST",
        data: "uid="+uid,
        dataType: "html",
        success: function (data, textStatus, xhr) {
                //Written here
              }

为什么会这样?

var div=new Array();
div[0]=15;
div[1]=96;
div[2]=30;
var i=2;
$('#share_button_'+div[i]).mouseover(function(){
    $('#share_button_'+div[i]).attr("src","img/share-hover.jpg");
});
$('#share_button_'+div[i]).mouseout(function(){
    $('#share_button_'+div[i]).attr("src","img/share-button-en.jpg");
});
var j=1;
$('#share_button_'+div[j]).mouseover(function(){
    $('#share_button_'+div[j]).attr("src","img/share-hover.jpg");
});
$('#share_button_'+div[j]).mouseout(function(){
    $('#share_button_'+div[j]).attr("src","img/share-button-en.jpg");
})
4

0 回答 0