checkbox和radio回显
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>form回显</title>
<link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<label class="checkbox-inline"><input type="checkbox" value="爱情" name="type">爱情</label>
<label class="checkbox-inline"><input type="checkbox" value="动作" name="type">动作</label>
<label class="checkbox-inline"><input type="checkbox" value="科幻" name="type">科幻</label>
<label class="radio-inline"><input type="radio" value="1" name="sequel">是</label>
<label class="radio-inline"><input type="radio" value="0" name="sequel">否</label>
<script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script>
var type = "爱情/动作";
var sequel = "1";
function matchBox(target, type, name) {
if (target.length > 0) {
var roleArr = target.split("/");
$.each(roleArr, function(index, roleName) {
$("input[type=" + type + "][name=" + name + "]").each(function() {
if ($(this).val() == roleName) {
$(this).attr("checked", true);
}
});
});
}
}
matchBox(type, "checkbox", "type");
matchBox(sequel, "radio", "sequel");
</script>
</body>
</html>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。