gpt4 book ai didi

javascript - 带有选定元素框的复选框

转载 作者:行者123 更新时间:2023-11-28 05:15:39 24 4
gpt4 key购买 nike

我需要您的帮助,如下图所示,我想知道带有所选元素的复选框的 JavaScript 代码,这些复选框应显示在所选元素框下方。谢谢

Checkbox

最佳答案

使用这个 HTML

<div class="taglist">
<label><input type="checkbox" value="2D Animation">2D Animation</label>
<label><input type="checkbox" value="3D Animation">3D Animation</label>
<label><input type="checkbox" value="Animatronics">Animatronics</label>
<label><input type="checkbox" value="Architectural">Architectural</label>
<label><input type="checkbox" value="Cartoon">Cartoon</label>
<label><input type="checkbox" value="Cell Animation">Cell Animation</label>
<label><input type="checkbox" value="Character Animation">Character Animation</label>
<label><input type="checkbox" value="Cut & Paste">Cut & Paste</label>
<label><input type="checkbox" value="Doodle">Doodle</label>
<label><input type="checkbox" value="HDR">HDR</label>
<label><input type="checkbox" value="High Speed">High Speed</label>
<label><input type="checkbox" value="Illustration">Illustration</label>
<label><input type="checkbox" value="Live Action">Live Action</label>
<label><input type="checkbox" value="Macro">Macro</label>
<label><input type="checkbox" value="Motion Design">Motion Design</label>
<label><input type="checkbox" value="Motion Graphics">Motion Graphics</label>
<label><input type="checkbox" value="Moving Installation">Moving Installation</label>
</div>

使用这个 html 代码和这个脚本

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
function updateTextArea() {
var allVals = [];
$('.taglist :checked').each(function(i) {

allVals.push((i!=0?"\r\n":"")+ $(this).val());
});
$('#video0_tags').val(allVals).attr('rows',allVals.length) ;

}
$(function() {
$('.taglist input').click(updateTextArea);
updateTextArea();
});
</script>

供引用http://jsfiddle.net/7b5fk/1/

关于javascript - 带有选定元素框的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39328274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com