如何将html页面中的div内容加载到主页上的div中? [英] How can I load div content from html pages into a div on main page?

查看:268
本文介绍了如何将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) {
	//


这篇关于如何将html页面中的div内容加载到主页上的div中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆