js实现获取值传到input里边

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Document</title>
<style>
</style>
<script>
function checkAll(e, itemName, thisValue){
var target = document.getElementById('arrayid');
var targetValue = target.value;
var inputs = document.getElementsByName(itemName);
if (e.checked == true) {
targetValue += thisValue + ',';
} else {
targetValue = targetValue.replace(thisValue + ',', '');
}
target.value = targetValue;
for(var i=0; i<inputs.length; i++){
inputs[i].checked = e.checked;
}
}
</script>
</head>
<body>
<form>
<p>
<input type="checkbox" value="1001" name="1001" id="1001" onclick="checkAll(this, 'mk1001', '1001')">
<label for="1001">复选1</label>
<input name="mk1001" type="checkbox" id="mk1001" value="1" />
<input name="mk1001" type="checkbox" id="mk1002" value="2" />
<input name="mk1001" type="checkbox" id="mk1003" value="3" />
<input name="mk1001" type="checkbox" id="mk1004" value="4" />
<input name="mk1001" type="checkbox" id="mk1005" value="5" />
</p>
<p>
<input type="checkbox" value="1002" name="1002" id="1002" onclick="checkAll(this, 'mk1002', '1002')">
<label for="1002">复选2</label>
<input name="mk1002" type="checkbox" id="mk1001" value="6" />
<input name="mk1002" type="checkbox" id="mk1002" value="7" />
<input name="mk1002" type="checkbox" id="mk1003" value="8" />
<input name="mk1002" type="checkbox" id="mk1004" value="9" />
<input name="mk1002" type="checkbox" id="mk1005" value="10" />
</p>
<p>
<input type="checkbox" value="1003" name="1003" id="1003" onclick="checkAll(this, 'mk1003', '1003')">
<label for="1003">复选3</label>
<input name="mk1003" type="checkbox" id="mk1001" value="11" />
<input name="mk1003" type="checkbox" id="mk1002" value="12" />
<input name="mk1003" type="checkbox" id="mk1003" value="13" />
<input name="mk1003" type="checkbox" id="mk1004" value="14" />
<input name="mk1003" type="checkbox" id="mk1005" value="15" />
</p>
<p>
<input type="checkbox" value="1004" name="1004" id="1004" onclick="checkAll(this, 'mk1004', '1004')">
<label for="1004">复选4</label>
<input name="mk1004" type="checkbox" id="mk1001" value="11" />
<input name="mk1004" type="checkbox" id="mk1002" value="12" />
<input name="mk1004" type="checkbox" id="mk1003" value="13" />
<input name="mk1004" type="checkbox" id="mk1004" value="14" />
<input name="mk1004" type="checkbox" id="mk1005" value="15" />
</p>
<p>
请把复选1,2,3的值传到以下的框中,中间以,号分隔
</p>
<p>
<input type="text" id="arrayid" />
</p>
</form>
</body>
</html>
用js实现获取值传到input里边。
分类:
JavaScript
标签:
javascript
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述