0
我在DOM中有一個元素,我用它作爲其他表單的模板,並最終被克隆很多次。由於所有的克隆,我有幾個元素擁有所有相同的ID。除了刪除每個克隆上的id屬性外,我還希望刪除該模板,因爲它在頁面視圖中顯示,但沒有任何內容。我的模板看起來像這樣刪除被克隆的模板ID
模板克隆
<div id="listBody">
<div id="template" class="col-md-3 panel ">
<div class="panel-body">
<div class="embed-responsive embed-responsive-4by3 text-light">
<img class="courseImage embed-responsive-item" src="http://www.w3devcampus.com/wp-content/uploads/logoAndOther/logo_JavaScript.png" alt="cover">
<div class="embed-overlay"></div>
<div class="embed-bar embed-bar-bottom">
<div class="pull-right">
<i class="icon-calendar fa-fw"></i> Sep 12, 2015
</div>
<div>
<a href="#" class="visible mr-1x"><i class="visible icon-share fa-fw"></i> Share</a>
<a href="#" class="visible"><i class="icon-star visible fa-fw"></i> Favourites</a>
</div>
</div>
</div><!-- /.embed -->
<h4 class="templateName"><strong>@*Course name stuff goes in here*@</strong></h4>
<p class="help-block"><small>by: <a href="#" class="mr-2x templateInstructor">@*Instructor stuff goes in here*@</a> - <span class="ml-2x"><i class="fa fa-tag fa-fw"></i>@*Course TAGS stuff goes in here*@</span></small></p>
<p class="templateDescription" width="100px" text-overflow="elipses" overflow="hidden" white-space="nowrap" maxlength="200">@*Description stuff goes in here*@</p>
<a href="#" id="openModalButton" class="showModal btn btn-sm btn-link text-dark"><i class="fa fa-long-arrow-right fa-fw"></i> READ MORE</a>
</div><!-- /.panel-body -->
</div><!-- /.panel -->`
您使用克隆模板的代碼是什麼?或者,您是否正在手動複製和粘貼代碼? – jkdev
如果您使用jQuery來克隆元素,您需要使用此'removeAttr(「id」)。'如果你想爲你的元素添加一個唯一的ID,你就可以看到這篇文章:http://stackoverflow.com/questions/10126395/how-to-jquery-clone-and-change-id – Franco
@Franco感謝那個頁面可能會幫助你 – NVA