根据复选框状态隐藏或显示 div
Hide or show div based on checkBox status
如何在 ASP.NET Core 2.2 with Razor 中根据复选框状态显示或隐藏 div 元素?
我有这个但是没用:
<script>
$(function() {
$('#gridCheck1').change(function() {
$('#ShowHideMe').toggle($(this).is(':checked'));
});
});
</script>
<div class="form-group row">
<div class="col-sm-2">Checkbox</div>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck1">
<label class="form-check-label" for="gridCheck1">
Example checkbox
</label>
</div>
</div>
</div>
<div id="ShowHideMe">
<p>some content</p>
</div>
这是我在项目文件夹中的库:
如果您想在不显示 div 的情况下开始,请添加 style="display:none"
。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<script>
$(function() {
$('#gridCheck1').change(function() {
$('#ShowHideMe').toggle($(this).is(':checked'));
});
});
</script>
<div class="form-group row">
<div class="col-sm-2">Checkbox</div>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck1">
<label class="form-check-label" for="gridCheck1">
Example checkbox
</label>
</div>
</div>
</div>
<div id="ShowHideMe" style="display:none">
<p>some content</p>
</div>
如何在 ASP.NET Core 2.2 with Razor 中根据复选框状态显示或隐藏 div 元素?
我有这个但是没用:
<script>
$(function() {
$('#gridCheck1').change(function() {
$('#ShowHideMe').toggle($(this).is(':checked'));
});
});
</script>
<div class="form-group row">
<div class="col-sm-2">Checkbox</div>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck1">
<label class="form-check-label" for="gridCheck1">
Example checkbox
</label>
</div>
</div>
</div>
<div id="ShowHideMe">
<p>some content</p>
</div>
这是我在项目文件夹中的库:
如果您想在不显示 div 的情况下开始,请添加 style="display:none"
。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<script>
$(function() {
$('#gridCheck1').change(function() {
$('#ShowHideMe').toggle($(this).is(':checked'));
});
});
</script>
<div class="form-group row">
<div class="col-sm-2">Checkbox</div>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck1">
<label class="form-check-label" for="gridCheck1">
Example checkbox
</label>
</div>
</div>
</div>
<div id="ShowHideMe" style="display:none">
<p>some content</p>
</div>