首页 新闻 会员 周边

请问下拿到了复选框的数据后,如何绑定复选框勾选

0
[已解决问题] 解决于 2018-04-18 09:17
var name="超级管理员,学生,教师";
<input type="checkbox" name="ChekRole" value="超级管理员">超级管理员 <input type="checkbox" name="ChekRole" value="学生">超级管理员 <input type="checkbox" name="ChekRole" value="教师">超级管理员

修改的时候,拿到了复选框要勾选的数据,然后怎么处理name,然后让checkbox勾选上。

你猜丶的主页 你猜丶 | 初学一级 | 园豆:183
提问于:2018-04-17 18:20
< >
分享
最佳答案
0
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="checkbox" name="ChekRole" value="超级管理员">超级管理员
    <input type="checkbox" name="ChekRole" value="学生">学生
    <input type="checkbox" name="ChekRole" value="教师">教师
</body>
<script>
    var name = "超级管理员,学生,教师"
    var names = name.split(",")
    var inputs = document.getElementsByTagName('input')

    for (const i in inputs) {
        for (const n in names) {
            if (names[n]===inputs[i].value) {
                inputs[i].checked = true
            }
        }
    }
    
</script>

</html>

不知道符合你的要求不。

奖励园豆:5
ohyex | 小虾三级 |园豆:1496 | 2018-04-17 20:15

非常棒

你猜丶 | 园豆:183 (初学一级) | 2018-04-18 09:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册