[英]How to create list in javascript
我想在 JS 中创建列表,并且必须通过选中该特定字符串附近的复选框来填充“字符串”对象。 此外,当复选框未选中时,必须从列表中删除该特定字符串。
请帮我构建这段代码。
<div class="row panel panel-default c-panel">
<div class="panel-heading c-phead">LIST</div>
<div class="panel-body">
<table class="table table-striped" id="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Customer</th>
<th scope="col">Checked/Unchecked</th>
</tr>
</thead>
<tbody>
<c:forEach items="${values}" varStatus="status" var="allval">
<tr>
<td>${status.index + 1}</td>
<td>${getVlaue1()}</td>
<td>${getVlaue2()}</td>
<td>
<input type="checkbox" class="custom-control-input" id="check1" value="${getVlaue1()}">
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
脚本 >>
$(document).ready(function(){
$('#check1').click(function(){
});
$('#table').DataTable();
});
你能分享一下代码片段吗?
JavaScript 中的列表称为数组。 如果您正在学习 JavaScript,我强烈建议初学者使用 W3Schools,以全面了解该语言及其工作原理。 但是关于数组,这个链接描述了它们是什么,如何创建它们,并展示了一些例子:
您可以使用简单的数组:
const myArray = ['string1', 'string2', 'string3'] /* To add new element use .push() function: */ myArray.push('string4') /* To remove specific element you can use: */ const index = myArray.indexOf('string3') if (index > -1) { myArray.splice(index, 1) } console.dir(myArray)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.