我在创建按钮时使用 append()。如何在附加文本中包含 ?
基本上我想这样做
<button type="button" class="btn btn-default" id="test1" >
<span class="glyphicon glyphicon-arrow-left"></span>
</button>
这里
$( '<button />' , { class: 'btn btn-default', type: 'button', id: 'test1' })
最佳答案
你也可以像这样使用html属性
$('<button />', {
class: 'btn btn-default',
type: 'button',
id: 'test1',
html: '<span class="glyphicon glyphicon-arrow-left"></span>'
});
var b = $( '<button />' , { class: 'btn btn-default', type: 'button', id: 'test1', html: '<span class="glyphicon glyphicon-arrow-left"></span>' });
$('body').append(b);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
关于javascript - 使用 append() 时在按钮内添加跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29270531/