我从codeopen那里得到了这个代码
https://codepen.io/monty5811/pen/xVgrzB#code-area
我希望将其嵌入到我的网页中
所以经过一番研究之后,我尝试了以下类似方法。
但这不能按预期工作。
这是我的html头
<head>
<meta charset="utf-8" />
<title>Semantic UI CDN</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.11.8/semantic.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.11.8/semantic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.css"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.js"></script>
<script>
$('.dropdown').dropdown({
label: {
duration: 0,
},
debug: true,
performance: true,
});
$('.ui.checkbox')
.checkbox({
onChecked() {
const options = $('#members_dropdown > option').toArray().map(
(obj) => obj.value
);
$('#members_dropdown').dropdown('set exactly', options);
},
onUnchecked() {
$('#members_dropdown').dropdown('clear');
},
});
</script>
</head>
身体:
<body>
<div class="ui hidden divider"></div>
<div class="ui stackable grid container">
<div class="eight wide column">
<form class="ui form" method="post">
<div class="field ">
<label class="" for="id_members">Members</label>
<select multiple="multiple" class="ui fluid search dropdown" id="members_dropdown" multiple="" name="members">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div id="dtBox"></div>
<div class="ui toggle checkbox">
<input type="checkbox" id="selectall">
<label>Select all</label>
</div>
<p>
</form>
</div>
</div>
</body>
答案 0 :(得分:1)
只需从头替换脚本并放入结尾。这是工作代码。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Semantic UI CDN</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.11.8/semantic.min.css"/>
</head>
<body>
<div class="ui hidden divider"></div>
<div class="ui stackable grid container">
<div class="eight wide column">
<form class="ui form" method="post">
<div class="field ">
<label class="" for="id_members">Members</label>
<select multiple="multiple" class="ui fluid search dropdown" id="members_dropdown" multiple="" name="members">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div id="dtBox"></div>
<div class="ui toggle checkbox">
<input type="checkbox" id="selectall">
<label>Select all</label>
</div>
<p>
</form>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.js"></script>
<script>
$('.dropdown').dropdown({
label: {
duration: 0,
},
debug: true,
performance: true,
});
$('.ui.checkbox')
.checkbox({
onChecked() {
const options = $('#members_dropdown > option').toArray().map(
(obj) => obj.value
);
$('#members_dropdown').dropdown('set exactly', options);
},
onUnchecked() {
$('#members_dropdown').dropdown('clear');
},
});
</script>
</body>
<html>