开发者

jQuery .clone() refreshes the page in safari

开发者 https://www.devze.com 2023-04-09 00:48 出处:网络
When I call var newElement = $(someElement).clone(); It refreshes the page immediately in Safari. I use jQuery v1.6.4. and Safari v5.1. In Chrome and Firefox the above call works perfectly.

When I call

var newElement = $(someElement).clone();

It refreshes the page immediately in Safari. I use jQuery v1.6.4. and Safari v5.1. In Chrome and Firefox the above call works perfectly.

Here is the code that refreshes the page in safari.

function resetAllAudioPieces()
{
    var audioPieces = $(".audio-piece");
    audioPieces.each(function(index){
        var newElement = $(audioPieces[index]).clone();
        $(audioPieces[index]).replaceWith(newElement);
        $(audioPieces[index]).removeClass("playing");
        $(audioPieces[index]).disableSelection();
    });
    return;
}


$("a#stop").live('click', function(e){
   开发者_C百科resetAllAudioPieces();
   e.preventDefault();
});

When I click the "#stop" link, the page refreshes. Is this a bug in jQuery clone() ? Please help.


Can you try without the "return;" and switch the preventDefault position ?

function resetAllAudioPieces()
{
    var audioPieces = $(".audio-piece");
    audioPieces.each(function(index){
        var newElement = $(audioPieces[index]).clone();
        $(audioPieces[index]).replaceWith(newElement);
        $(audioPieces[index]).removeClass("playing");
        $(audioPieces[index]).disableSelection();
    });
    // return;
}


$("a#stop").live('click', function(e){
   e.preventDefault();
   resetAllAudioPieces();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消