我有以下HMTL:使用prependTo元素消失
<div class="modal fade in" id="data-confirmation-modal" tabindex="-1" role="dialog" aria-labelledby="data-confirmation-modal-label">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<span class="fa fa-exclamation-triangle"></span>
<h4 class="modal-title" id="data-confirmation-modal-label">Titile</h4>
</div>
<div class="modal-body">
<p>Example</p>
</div>
<div class="modal-footer">
<button id="" type="button" class="btn-confirm">Conform</button>
<button type="button" class="btn-cancel" autofocus="" data-dismiss="modal">Avbryt</button>
</div>
</div>
</div>
</div>
我想創建一個表單元素,並把表單元素內模態含量javascipt的:
$form = $("<form></form>");
$form.prependTo($('.modal-content'));
當我使用上面的代碼我模態是空的。希望得到一些幫助。 我想的HTML如下:
<div class="modal fade in" id="data-confirmation-modal" tabindex="-1" role="dialog" aria-labelledby="data-confirmation-modal-label">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form>
<div class="modal-header">
<span class="fa fa-exclamation-triangle"></span>
<h4 class="modal-title" id="data-confirmation-modal-label">Titile</h4>
</div>
<div class="modal-body">
<p>Example</p>
</div>
<div class="modal-footer">
<button id="" type="button" class="btn-confirm">Conform</button>
<button type="button" class="btn-cancel" autofocus="" data-dismiss="modal">Avbryt</button>
</div>
</form>
</div>
</div>
</div>
如果我沒有弄錯,['prependTo()'](http://api.jquery.com/prependto/)不用於包裝。它用於在目標元素的開始處添加/傳輸另一個元素 – Swellar