springboot怎么把数据传给前端:springboot 如何引入前端 bootstrap?
这种问题网上一搜一大堆,你可以具体找一篇文章试试,遇到问题可以针对相关问题去提问。springboot通过jar包方式引入bootstrap_个人文章 - SegmentFault 思否 这不是查查就
顺晟科技
2022-10-18 12:14:57
107
我想使复选框输入具有动态值取决于:选中。
如果选中复选框,则值为";true";
<代码><;输入类型=";复选框";值=";真";选中=";已检查";>;或如果未选中复选框,则值为";false";
<代码><;输入类型=";复选框";值=";错误";>;
我这样做是因为我通过Ajax提交表单,并且我使用了jQuery.searialize()
这个领域更像是一个开关。
这可能吗?谢谢!
顺晟科技:
如果我理解这个问题,你想改变复选框的值,取决于它是否被选中?这可以通过Ajax来实现。您必须为复选框输入添加一个ID(“#checkbox1 ”)。
这里有一个解决方案:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" data-switchval value="true" checked="checked">
然后将其添加到代码中以获取值:
document.querySelector('[data-switchval]').addEventListener('change', e => {
e.target.value = e.target.checked
console.log('current value of checkbox:', e.target.value)
})
jQuery方式
<input type="checkbox" value="true" checked="checked">
<代码><;script SRC=“ https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js ”>;<;/script>;<;input type=“ checkbox ” data-switchval value=“ true ” checked=“ checked ”>;
[后记]刚刚意识到这个问题被标记为jQuery..这是Vanillajs的版本。
<input type="checkbox" value="false">
<代码><;input type=“ checkbox ” data-switchval value=“ true ” checked=“ checked ”>;
您可以为Change事件添加事件侦听器。
$('[data-switchval]').change(function() {
$(this).val($(this).prop('checked'));
console.log('current value of checkbox:', $(this).val())
})
<代码><;输入类型=“复选框”>;
05
2022-12
02
2022-12
02
2022-12
29
2022-11
29
2022-11
24
2022-11