Home >Web Front-end >JS Tutorial >JS sample code to change p display status when clicking on checkbox
This article will share with you a JS sample code to implement clicking on the check box to change the display status of p. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
First on the page:
<p class="row cl"> <label class="form-label col-xs-4 col-sm-3" style="width: 20%"><span class="c-red">*</span>是否存在促销活动:</label> <p class="formControls col-xs-8 col-sm-9 skin-minimal"> <p class="check-box"> <input type="checkbox" value="1" id="isHaveActive" > <label for="isHaveActive"> </label> </p> </p> </p> <p id="active" name="active" style="display:none;"> <p class="row cl" > <label class="form-label col-xs-4 col-sm-3" style="width: 20%"><span class="c-red">*</span>现价:</label> <p class="formControls col-xs-8 col-sm-9"> <input type="number" step="0.01" class="input-text" value="${priceChange.price}" placeholder="" id="price" name="price" > 元/L </p> </p> <p class="row cl" > <label class="form-label col-xs-4 col-sm-3" style="width: 20%"><span class="c-red">*</span>活动名:</label> <p class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="${priceChange.active_name}" placeholder="" id="active_name" name="active_name" > </p> </p> <p class="row cl" > <label class="form-label col-xs-4 col-sm-3" style="width: 20%"><span class="c-red">*</span>距挂牌价:</label> <p class="formControls col-xs-8 col-sm-9"> <input type="number" step="0.01" class="input-text" value="${priceChange.gap_guapai}" placeholder="" id="gap_guapai" name="gap_guapai" > 元/L </p> </p> <p class="row cl" > <label class="form-label col-xs-4 col-sm-3" style="width: 20%"><span class="c-red">*</span>促销活动形式:</label> <p class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="${priceChange.activity_form}" placeholder="" id="activity_form" name="activity_form" > </p> </p> <p class="row cl" > <label class="form-label col-xs-4 col-sm-3" style="width: 20%"><span class="c-red">*</span>促销活动优惠幅度:</label> <p class="formControls col-xs-8 col-sm-9"> <input type="number" step="0.01" class="input-text" value="${priceChange.activity_gap}" placeholder="" id="activity_gap" name="activity_gap" > 元/L </p> </p> </p>
Then the implementation in jquery
jQuery(document).ready(function($) { //是否添加活动内容 $("#isHaveActive").change(function(){ var p = $("#active"); p.css("display") === "none" && p.show() || p.hide(); });
Related recommendations:
JS click on the link to switch Implementation method of displaying hidden content
js method of clicking to select text_javascript skills
js click return to jump to the specified page implementation process_ javascript skills
The above is the detailed content of JS sample code to change p display status when clicking on checkbox. For more information, please follow other related articles on the PHP Chinese website!