<!DOCTYPE html>
<html lang="zh">
<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>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<style>
.bd {display: none;}
</style>
</head>
<body>
<input type="checkbox" name="purpose_id[]" class="purpose" value="13">家庭装饰
<input type="checkbox" name="purpose_id[]" class="purpose" value="17">礼物馈赠
<p class="bd">1放家庭装饰 input</p>
<p class="bd">2放礼物馈赠 input</p>
<script>
$(function(){
var onff0 = true;
var onff1 = true;
$('.purpose:eq(0):checkbox').on('click',function(){
if (onff0) {
$('.bd:eq(0)').css('display','block');
} else {
$('.bd:eq(0)').css('display','none');
}
onff0 = !onff0;
})
$('.purpose:eq(1):checkbox').on('click',function(){
if (onff1) {
$('.bd:eq(1)').css('display','block');
} else {
$('.bd:eq(1)').css('display','none');
}
onff1 = !onff1;
})
})
</script>
</body>
</html>
First add data-v to p of bd corresponding to the value above
p Adding an attribute can correspond to the check box. The writing method of judging by index will be useless if the position is slightly changed
$(".purpose").on('change',function(){
});
<input type="checkbox" name="purpose_id[]" class="purpose" onchange="check1();" data="1" value="13">Home decoration
What function are you trying to use? I don’t understand. . . . . .