无法将引导程序类添加到javascript innerHTML

时间:2019-06-16 00:25:26

标签: javascript html bootstrap-4

var result = document.getElementById("result")

//can't add bootstrap classes to <div> and <table>
<div class="container"><table class="table">

result.innerHTML = "<div><table><thead><tr><td>Column A</td>

1 个答案:

答案 0 :(得分:0)

首先,在您的代码中,外部div似乎没有附加ID,请像这样调用div:

<div id="result>

要将引导程序添加到html中,您必须首先导入css文件,并将其放在html的head元素中,例如:

<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>

然后将javascript,jquery和popper.js文件添加到html正文的末尾:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

还请确保使用如上所示的script标签将您的javascript添加到html中,或将其添加到script标签中

<script>
some js
</script>