【发布时间】:2019-05-15 16:32:32
【问题描述】:
这是我的简单示例。
这个小应用程序使用 jQuery 创建 20 个复选框,使用 #checkbox-template 作为模板。标签的for 属性和每个输入的id 被更改为唯一。
- 预期行为:每个复选框都应该是可选的。实际
- 行为:复选框不可选择。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My Example</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
</head>
<body>
<!-- TEMPLATE -->
<templates style="display: none">
<div id="checkbox-template">
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="podcast-checkbox">
<input type="checkbox" id="podcast-checkbox" class="mdl-checkbox__input" />
</label>
</div>
</templates>
<!-- List -->
<div id="my-list"></div>
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script>
$(function() {
for (var i = 0; i < 20; i++) {
var newItem = $("<div>");
newItem.html($("#checkbox-template").html());
newItem.find("#podcast-checkbox-container").attr("for", "the-item-" + i);
newItem.find("#podcast-checkbox").attr("id", "the-item-" + i);
componentHandler.upgradeElement(newItem.get(0));
newItem.appendTo("#my-list");
}
});
</script>
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
</body>
</html>
【问题讨论】:
标签: javascript jquery dom material-design-lite