简体   繁体   English

如何通过单击菜单中的Li将HTML页面从href加载到div中?

[英]How to load a html page from href into a div by clicking a Li inside a menu?

i have a ul menu 我有一个ul菜单

                   <ul>
                      <li>
                        <a href="../folder/rules.html" id="rules">rules</a>
                    </li>
                    <li>
                        <a href="../folder/service.html" id="service">Service</a>
                    </li>
                    </ul>

and i want when the user press on a tag the html page load on <div id=result> that i have in bottom of this page. 我想当用户按下标签时,我在此页面底部的<div id=result>上加载html页面。

i try that with jquery as i found but the html in href load on new tab there is my code: 我尝试用jquery进行尝试,但是在新选项卡上的href中的html加载了我的代码:

  <script src="http://code.jquery.com/jquery-1.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(funtction(){
        $("#rules").click(function()
             $('#result').load(rules.html);
        });
        $("#service").click(function(){
            $('#result').load(service.html);
        })
    });
     </script>

Read up .load() | 阅读.load() | jQuery API Documentation jQuery API文档

You need to pass the paths of HTML files as string . 您需要将HTML文件的路径作为string传递。

Replace 更换

$('#result').load(rules.html);

with

$('#result').load('../folder/rules.html');

EDIT: 编辑:

In response to your comment, try this: 为了回应您的评论,请尝试以下操作:

$("#rules").click(function(event)
     $('#result').load('../folder/rules.html');
     event.preventDefault(); // so that the event does not bubble up
});

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

相关问题 如何通过单击菜单中的Li将HTML页面加载到DIV中? - How to load a HTML-page into a DIV by clicking a Li inside a menu? 如何通过单击“ include(&#39;menu.html&#39;)”菜单内的Li来将HTML页面加载到DIV中 - How to load a HTML-page into a DIV by clicking a Li from inside a menu on an 'include('menu.html')' 单击菜单列表时如何在同一页面的DIV中加载HTML页面? - How to load HTML page in DIV of the same page when clicking the menu list? 如何在单击其中一个时关闭下拉 div<li> 在它里面还是在div外面? - How to close a dropDown div on clicking on one of the <li> inside it or outside the div? 如何使用Angular在菜单单击上的div内加载HTML? - How to load html inside a div on menu click using angular? HTML 页面在点击 href 后不加载,但在重新加载后加载 - HTML page does not load after clicking href, but after a reload it does 如何通过单击html页面中的菜单从jsp调用Java方法? - How to call a java method from jsp by clicking a menu in html page? 如何在单击带有href =#的链接时停止页面加载? - How to stop page load while clicking on link with href=#? 通过单击home.html页面上的href img,我想在page2.html上显示该href的详细信息 - By clicking an href img from home.html page i want to show details of that href on page2.html jQuery单击href后将图像加载到div - jquery load image to div after clicking href
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM