简体   繁体   English

Ajax内容加载问题

[英]Ajax content loading issues

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. 现在,以下代码已禁用CTRL+CLICK短代码来在新标签页中打开网址。 The new CSS and JS are not applying if they are not already exist in the previous page. 如果新的CSS和JS在上一页中尚不存在,则不适用。 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;
 });

What you want to do is modify the handler to use prevent default instead of returning false. 您要做的是修改处理程序以使用prevent default而不是返回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. 对于不适用的JS和CSS,我们需要一个有效的示例来提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM