js file
var i = 0;
var original = document.getElementById('middle-section');
document.getElementById('btn').onclick = duplicate();
function duplicate() {
var clone = original.cloneNode(true); // "deep" clone
clone.id = "middle-section" + ++i;
// or clone.id = ""; if the divs don't need an ID
original.body.appendChild(clone);
}
css file
.middle-section-name{
position: absolute;
left: 500px;
top: 850px;
width: 200px;
height: 40px;
background-color: #aaaaaa;
border: 2px hidden;
}
.middle-section-edit{
position: absolute;
left: 700px;
top: 840px;
}
.middle-section-edit img{
width: 20px;
margin: 5px;
}
view
<body>
<div class="container-fluid">
<div class="header">
<p>header</p>
</div>
</div>
<div class="container">
<div class="logo">
<div class="logo-part">
<p>logo</p>
</div>
<div class="logo-name">
<P>logo name</P>
</div>
<div class="logo-edit">
<%= image_tag 'edit-logo.png'%>
</div>
</div>
<div class="top-main-section">
<div class="top-main-section-area">
<p>top main section</p>
</div>
<div class="top-main-section-edit">
<%= image_tag 'settings-logo.png'%>
</div>
</div>
<div class="top-banner-section">
<div class="top-banner-section-area">
<p>top banner section</p>
</div>
<div class="top-banner-section-edit">
<%= image_tag 'settings-logo.png'%>
</div>
</div>
<div class="middle-section" id="middle-section">
<div class="middle-section-name">
</div>
<div class="middle-section-edit">
<%= image_tag 'settings-logo.png'%>
</div>
<div class="middle-section-area">
<p>carosel</p>
</div>
</div>
</div>
<input type="button" value="click" id="btn" onclick="duplicate()"/>
</body>
我新的軌道顯示它,我嘗試添加DIV部分上點擊顯示在view.I嘗試與此代碼但仍然無法正常工作,控制檯中的錯誤爲cannot read property clone node of null
。我嘗試了不同的方式來使它工作,但我仍然失敗了。下面是HTML文件,JS文件和下面的CSS文件,錯誤號爲cloneNode undefined
。 CSS和HTML文件正在工作,但JQuery不會
這對我來說不起作用。 '同樣的問題在這裏'不能讀取屬性cloneNode是未定義的' –