English 中文(简体)
现行网页从重载到现时
原标题:Stopping the Current page from reloading when active
  • 时间:2010-10-29 15:39:07
  •  标签:
  • jquery

我愿知道,是否有办法使目前的班子无法用j Query重新上载?

例如,当你上下几页时,如果用户再次点击该链接,就会重新上页。 因此,如果你有某种估计,它就得起。

如果有人能给我一手的话,我将非常赞赏。

感谢你,

这是我迄今为止所做的:

$(function() {
    $page = jQuery.url.attr("file");
    if (!$page) {
        $page =  index.html ;
    }
    $( ul.navigation li a ).each(function() {
        var $href = $(this).attr( href );
        if (($href == $page) || ($href ==   )) {
            $(this).addClass( current );
        } else {
            $(this).removeClass( current );
        }
    });
});
最佳回答

你必须赶上点击事件并取消。 见我在以下评论中增加的第一部分:

$(function(){
 $page = jQuery.url.attr("file");
 if(!$page) {
  $page =  index.html ;
 }
 $( ul.navigation li a ).each(function(){
  var $href = $(this).attr( href );
  if ( ($href == $page) || ($href ==   ) ) {
   $(this).addClass( current );

   /** ADDED BELOW **/
   $(this).click(function(event) {
     event.preventDefault();
     event.stopPropagation();
   });
   /** ADDED ABOVE **/

  } else {
   $(this).removeClass( current );
  }
 });
});
问题回答

你们可以通过替换(这笔)来消除这一联系。 加上:

$(this).addClass( current ).find("a").click( function() {
  return false;                     
})

This has worked for me in the past but have just seen Ben s update and am interested if mine and his answers will both work or whether mine is flawed? Is event.preventDefault(); and event.stopPropagation() the better option?

如何动态地将斜线添加到本页的链接中? 蒸发了与尿液中一台散射机的连接。 (DOM元件有一个名为“hash”的财产,可用于此目的)





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签