-1
通过getmdl.io,复选框元素是:如何创建一个MDL复选框元素
#d{
padding:20px
<script src="https://code.getmdl.io/1.1.3/material.min.js"></script>
<link href="https://code.getmdl.io/1.3.0/material.deep_purple-blue.min.css" rel="stylesheet"/>
<div id="d">
<label for="chkbox1" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
<input type="checkbox" id="chkbox1" class="mdl-checkbox__input">
<span class="mdl-checkbox__label">Checkbox</span>
</label>
,我尝试使用JS增加这个要素
function addCB(){
var cb = document.createElement('div');
cb.innerHTML = `<label for="chkbox1" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
<input type="checkbox" id="chkbox1" class="mdl-checkbox__input">
<span class="mdl-checkbox__label">Checkbox</span>
</label>`;
document.getElementById('d').appendChild(cb);
}
#d{
padding:20px
<script src="https://code.getmdl.io/1.1.3/material.min.js"></script>
<link href="https://code.getmdl.io/1.3.0/material.deep_purple-blue.min.css" rel="stylesheet"/>
<div id="d">
<button class="mdl-button mdl-js-button mdl-js-ripple-effect " onClick="addCB()">Add checkbox</button>
但设计不起作用,idk为什么,任何人都可以帮助我?
“_doesn't work_”不是问题描述。请解释代码应该做什么,以及它做了什么。 – Teemu