【问题标题】:Checkbox with selected items box带有所选项目的复选框
【发布时间】:2016-09-05 10:08:16
【问题描述】:

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

【问题讨论】:

  • document.getElementById("elementId").checked 将根据被检查的项目/选择器为您提供真值或假值。这就是你想要的吗?
  • 向我们展示代码,以便我们知道问题出在哪里。
  • 没有问题。我已经完成了该部分,但问题在于所选项目显示..它已解决..谢谢..

标签: javascript html css checkbox checkboxlist


【解决方案1】:

使用这个 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/

【讨论】:

  • 您好,请告诉我如何将所选项目并排放置?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-06
  • 2017-05-05
相关资源
最近更新 更多