weixin_33693070 2014-10-30 22:48 采纳率: 0%
浏览 17

Ajax内容加载问题

Following is my code which I am using to load contents dynamically. The issues which I am facing are the following:

Following code has now disabled CTRL+CLICK shortcode to open a url in a new tab. The new CSS and JS are not applying if they are not already exist in the previous page. Kindly let me know how can I resolve above mentioned issues?

 $(document.body).on("click", "nav a", function () {
      topen = $(this).attr("href");
      window.location.hash = $(this).attr("href");
      $("#main_wrapper").load( topen +" #main_wrapper > *");
      return false;
 });
  • 写回答

1条回答 默认 最新

  • weixin_33676492 2014-10-30 23:11
    关注

    What you want to do is modify the handler to use prevent default instead of returning false. Then you can check how the user activated the button and can act accordingly.

    $(document).ready(function() {
        $('a').on('click', function(e) {
            if(e.ctrlKey || e.button === 1) {
                return;
            }
            e.preventDefault();
            // Do the stuff when the anchor is just clicked.
        });
    });
    

    You can examine the Fiddle

    In terms of the JS and CSS not applying we would need a working example of this to be of more assistance.

    评论

报告相同问题?