javascript - 无法在表 td 中使用 Bootstrap Toggle?

标签 javascript html twitter-bootstrap

我使用 bootstraptoggle 生成 html 表如下。

var configTableDiv = document.getElementById('exportListContent');

output = '<tr><td><input id="toggle-mode" type="checkbox" checked data-toggle="toggle" data-onstyle="warning" data-offstyle="info"></td></tr>';

configTableDiv.innerHTML = configTableDiv.innerHTML + output;

但是相关功能或设计在表td中不起作用。它显示正常的复选框。有什么解决办法吗?

这是相关的 html 输出。

<td><input id="toggle-mode" type="checkbox" checked="" data-toggle="toggle" data-onstyle="warning" data-offstyle="info" data-on="Kite" data-off="InAppPurchase"></td>

最佳答案

您可以使用jquery来完成此操作。

var configTableDiv = document.getElementById('exportListContent');
output = '<tr><td><input id="toggle-mode" type="checkbox" checked data-toggle="toggle" data-onstyle="warning" data-offstyle="info"></td></tr>';
configTableDiv.innerHTML = configTableDiv.innerHTML + output;
$('#toggle-mode').bootstrapToggle();

var configTableDiv = document.getElementById('exportListContent');
output = '<tr><td><input id="toggle-mode" type="checkbox" checked data-toggle="toggle" data-onstyle="warning" data-offstyle="info"></td></tr>';
configTableDiv.innerHTML = configTableDiv.innerHTML + output;
$('#toggle-mode').bootstrapToggle();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet"/>
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<table id="exportListContent">
</table>

关于javascript - 无法在表 td 中使用 Bootstrap Toggle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42068559/

相关文章:

html - CSS - 背景覆盖 Bootstrap table-striped

jquery - 如何为文本添加滚动视差效果

java - 面板主体 Bootstrap 的一致显示

css - 图标题与图像边距对齐

javascript - 有人尝试在嵌入式环境中运行node.js 或原始v8 引擎吗?

html - 如何为列表中的元素添加背景颜色

javascript - 在 AngularJS 中使用 showType

Javascript检查目录中的文件是否可读可写或可执行

javascript - 为什么这个 JavaScript 代码组合数组的元素而不是添加元素?

java - CardPile 错误,无法编译。