【问题标题】:jquery load(), stop refresh the page after successjquery load(),成功后停止刷新页面
【发布时间】:2013-08-03 19:16:34
【问题描述】:

只是一个正常的加载功能,但是完成后,它似乎重新加载了整个页面。这是一个简化版:

<body>
    <div id="outer">
         <script>
               $(document).ready(function(){
                   alert('begin')

                   $("#portfolio").click(function(){
                        $("#inner").load("portfolio.html");
                        alert('finish')

                   });
              });
         </script>

         <header>
              <a href="" id="home">name</a>
              <a href="" id="portfolio">portfolio</a>
         </header>

    </div>
    <div id="inner"></div>
</body>

我在portfolio.html文件中写的都是一行文字,但以后会变得更完整的内容。警报只是为了确认正在发生的事情。

我也尝试过使用 $.get 方法加载内容(顺便说一句,它根本不起作用......)但同样重新加载了页面。

是否需要编写某种停止函数?但从我所读到的,通常没有必要。这应该很简单……

【问题讨论】:

标签: jquery get load reload


【解决方案1】:

You seem to have href set to nothing. Thats why its refreshing. Set it to #. 另外,您还缺少e.preventDefault。尝试将其添加到#portfolioclick 中。

 $("#portfolio").click(function(e){
   e.preventDefault(); 
   $("#inner").load("portfolio.html");
   alert('finish')
 });

【讨论】:

  • 天哪,我没有注意到,我把#去掉了。谢谢。
猜你喜欢
  • 2017-02-27
  • 2018-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-09
  • 2020-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多