插入复选框的值而不提交
insert value of check boxes without submitting
这是一个选择类和节的表单。当选择一个类时,将出现四个部分。我真的需要知道如何从这些复选框中获取输入,并确定哪个部分属于哪个类。如有需要,也请提供此代码的任何修改。谢谢你
无标题的文档
<script type="text/javascript">
function showMe (it, box) {
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;
}
function showMe2 (it) {
var vis = document.getElementById(it).style.display
if (vis == "block") { document.getElementById(it).style.display = "none"; }
else { document.getElementById(it).style.display = "block"; }
}
</script>
<style type="text/css">
.divstyle
{
display: none;
border: 1px solid #000;
height: 100px;
width: 200px;
}
</style>
</head>
<body>
<table>
<tr>
<td><input name="class[one]" type="checkbox" onclick="showMe('div1', this)" />
One</td>
</tr>
<tr>
<td><input name="class[two]" type="checkbox" onclick="showMe('div1', this)" />
Two</td>
</tr>
<tr>
<td><input name="class[three]" type="checkbox" onclick="showMe('div1', this)" />
Three</td>
</tr>
<tr>
<td><input name="class[four]" type="checkbox" onclick="showMe('div1', this)" />
Four</td>
</tr>
<tr>
<td><input name="class[five]" type="checkbox" onclick="showMe('div1', this)" />
Five
</td>
</tr>
<tr>
<td><input name="class[six]" type="checkbox" onclick="showMe('div1', this)" />
Six
</td>
</tr>
<tr>
<td><input name="class[seven]" type="checkbox" onclick="showMe('div1', this)" />
Seven</td>
</tr>
<tr>
<td><input name="class[eight]" type="checkbox" onclick="showMe('div1', this)" />
Eight</td>
</tr>
<tr>
<td><input name="class[nine]" type="checkbox" onclick="showMe('div1', this)" />
Nine</td>
</tr>
<tr>
<td><input name="class[ten]" type="checkbox" onclick="showMe('div1', this)" />
Ten</td>
</tr>
</table>
<div class="divstyle" id="div1">
<table>
<td><input name="sec[a]" type="checkbox" value="" />a</td>
<td><input name="sec[b]" type="checkbox" value="" />b</td>
<td><input name="sec[c]" type="checkbox" value="" />c</td>
<td><input name="sec[d]" type="checkbox" value="" />d</td>
</table>
</div>
</body>
</html>
您可以在复选框中设置ID,并将其传递给您的函数。
<td><input id="ten" name="class[ten]" type="checkbox" onclick="showMe('div1', this)" />
Ten</td>
showMe函数
document.getElementById('checked_box').value = box.id;
将值发送到一个隐藏字段
<input type="hidden" name="checked_box" id="checked_box" value="" />
不太确定你最终想要完成什么,但这是一个开始。
相关文章:
- Jquery表单验证插件-如果选中复选框,如何在提交时执行某些操作
- 如何获取所有选中复选框的所有值,然后将其提交到表单中
- 使用javascript提交表单并从字段/单选框/复选框/文本区域获取数据
- ASP MVC复选框表单提交问题
- 如何在将鼠标悬停在提交/锚点上时检查复选框是否已选中,并显示提示用户这样做的警报
- Rails 4:动态添加的复选框未提交
- 高级表单提交-单选、复选框和重定向
- 如何在提交时验证多个复选框
- 提交前验证超链接和复选框
- 为什么复选框在未选中时不提交任何数据
- 如何提交未选中复选框的值
- 如何使用javascript自动提交保存/重新填充的复选框
- 如何在提交时防止粘性复选框重置?(一页上有多个表格)
- Wordpress:提交后,我如何在搜索表单中保留市场复选框
- 通过javascript提交复选框的值
- 不带提交按钮的提交复选框状态
- 如何自动提交复选框
- 如何使用jQuery DataTables从所有页面提交复选框
- 如何通过jquery ajax提交复选框
- .net表单提交复选框标签在Internet Explorer中不工作