jQuery在DIV之间复制内容 [英] jQuery copying content between DIVs
本文介绍了jQuery在DIV之间复制内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个完全基于Java的网站上工作:加载该网站,然后所有页面都被Javascript拉入.
I am working on a website that I want to be entirely Javascript based: you load the website, then all the pages are pulled in by Javascript.
所以我这里就是我所拥有的:
So I here's what I have:
<span id="deathWormButton">Death Worm</span>
<div id="pageContent">
<p>Thanks for taking the time to view my portfolio!</p>
<p>Placeholder content</p>
<p>Placeholder content</p>
<p>Placeholder content</p>
<p>Placeholder content</p>
</div>
<div id="DeathWormPage" class="page">
<p>Thanks for taking the time to view my portfolio!</p>
<p>Placeholder content</p>
<p>Placeholder content</p>
<p>Placeholder content</p>
<p>Placeholder content</p>
</div>
这是我的jQuery:
And here's my jQuery:
$(document).ready(function()
{
$(".page").hide();
});
$("#deathWormButton").click(function()
{
$("#pageContent").innerHTML = $("#DeathWormPage").innerHTML;
});
但是它不起作用! (在此处查看)
But it doesn't work! (View here)
那么当单击deathWormButton
时如何将内容从div id="DeathWormPage"
复制到div id="pageContent"
?
So how do I copy content from the div id="DeathWormPage"
into div id="pageContent"
when the deathWormButton
is clicked?
推荐答案
jquery对象没有innerHTML属性.
jquery objects do not have an innerHTML property.
$(document).ready(function () {
$(".page").hide();
$("#deathWormButton").click(function () {
$("#pageContent").html($("#DeathWormPage").html())
})
});
也可以将其放在文档准备功能中,或者您引用的是不存在的内容.
Also, put it inside the document ready function or you are referencing a non-existant thing.
这篇关于jQuery在DIV之间复制内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文