<!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>
首先给bd的p加上data-v对应上面的value
p加个属性跟复选框能对应,那个通过index来进行判断的写法位置稍微一改动就没用
$(".purpose").on('change',function(){
});
<input type="checkbox" name="purpose_id[]" class="purpose" onchange="check1();" data="1" value="13">家庭装饰
你这是要做什么功能啊,没看明白。。。。。。