如何将html页面中的div内容加载到主页上的div中?

如何将html页面中的div内容加载到主页上的div中?

问题描述:

嘿那里



我在页面上有一个列表/链接

当我点击一个列表/链接项时,

我想将其他页面的div内容加载到主页面上的div。

我知道这可以通过下面的硬编码来完成。





Hey there

I have a list/link on a page
When I click a list/link item,
I want to load div content from other pages into a div on the main page.
I known that this can be done by hardcoding like below.


<div id="main1">
    <ul>
        <li >Home</li>
        <li >Work</li>
        <li >Contact</li>
    </ul>
</div>

<div id="main2"> </div>

<script>
    function load() {
        $("#main2").load("home.html #title");
    }
</script>





而不是将.html作为参数传递?

类似





Instead of this is it possible to pass the .html in as a parameter?
Something like

<li >Home</li>
         
            function load(url) {
                $("#main2").load( + url + "#title");
            }





感谢您对noob问题的任何帮助和道歉:)



Thanks for any help and apologies for the noob question :)

#main2)。load( home.html #title);
}
< / script>
("#main2").load("home.html #title"); } </script>





而不是将.html作为参数传递?

类似





Instead of this is it possible to pass the .html in as a parameter?
Something like

<li >Home</li>
         
            function load(url) {


#main2)。load(+ url + #title);
}
("#main2").load( + url + "#title"); }





感谢您对noob问题的任何帮助和道歉:)



Thanks for any help and apologies for the noob question :)


是的,有可能。

轻微修改加载功能:

Yes, it is possible.
Slight modification to the load function:
//The load function has an extra + sign before the url that should be removed and an addition space is required before the the #title to find the element with title as the id in the specified url page
function load(url) {
	//