开发者

jQuery: Hidden msg shows every time I get or refresh web page

开发者 https://www.devze.com 2023-04-02 06:15 出处:网络
I made msg which appears when \"Save\" button on web page is pressed and disappears after few sec, but there are two problems. First one is that when I click link to that page, I get msg right after w

I made msg which appears when "Save" button on web page is pressed and disappears after few sec, but there are two problems. First one is that when I click link to that page, I get msg right after web page appears. Here is the code:

    $(".success").fadeIn(1500).delay(2500).fadeOut(2000);

And here is some added code, which have problem with very short time of showing msg. Msg disappea开发者_如何学Gors in millisecond.

    $("#button").click(function(){
    $(".success").fadeIn(1500).delay(2500).fadeOut(2000);});

My friend told me that it might be cause of refreshing whole page, after clicking "Save" button.

Second problem is that if I click "Save" button on some other tab (I'm using jQuery tabs) it will send me back to the first tab. How could I stay on current tab after this action?


button is a link ? Maybe you just have to stop event propageation, have a look at this.

Basically just to

$("#button").click(function(evt){
$(".success").fadeIn(1500).delay(2500).fadeOut(2000);
evt.stopPropagation();
});


If you call this within $(document).ready or similar events functions, it will be executed immediately on all elements having class "success".

$(".success").fadeIn(1500).delay(2500).fadeOut(2000);

Since you did not post enough of your javascript implementation here, it is impossible to know for sure what the issue is. Neither do we know anything about the elements these lines act upon.

0

精彩评论

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

关注公众号