我有以下Hmtl:
var= appClass.myObj;
我正在尝试创建一个表单元素并将模态内容放在javascipt中的表单元素中:
<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>
当我使用上面的代码时,模态为空。会感激一些帮助。 我希望html如下:
$form = $("<form></form>");
$form.prependTo($('.modal-content'));
答案 0 :(得分:2)
$(".modal-content").children().wrapAll("<form></form>")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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>
.wrapAll()
打包所有内容答案 1 :(得分:0)
你可以使用jquery wrap http://api.jquery.com/wrap/用表单包装.modal-content 或者您可以使用表单重写整个html,例如
$('.modal-content').html('<form>'+$('.modal-content').html()+'</form>')
答案 2 :(得分:0)
您可以使用以下代码。
$(".modal-content").wrap("<form></form>").