jQuery是否选中了复选框Bootstrap开关 [英] Jquery if checkbox is checked Bootstrap switch
本文介绍了jQuery是否选中了复选框Bootstrap开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Bootstrap开关插件使我的复选框看起来像开关按钮.我需要检查jQuery中是否已选中该复选框.我在Google上搜索了很多,尝试了一些建议和代码段,但没有成功.
I use Bootstrap switch plugin to make my checkboxes looks like switch buttons. I need to check if the checkbox is checked in jQuery. I Googled a lot and I tried some advice and code snippets but without success.
我认为找到的最干净的代码是
I think the cleanest code I found is
$('#checkbox').attr('checked');
但是它仍然无法在我的网站上运行.我已经声明了jQuery.我尝试在非引导开关复选框上使用此代码段,但仍然没有成功.
but it still wont work on my website. I have declared jQuery in head. I try to use this snippets on non-bootstrap-switch-checkboxes but still no success.
JS:
<script>
$(function(){
$(".odeslat").click(function(){
$('#pozadavky').slideUp(100);
$('#datumpick').slideDown(300);
var typpaliva = 'nic';
var malpg = 'nic';¨
/***Important condition***/
if ($('#uho').attr('checked')) {
$.cookie("typpaliva", "Diesel");
}
else {
$.cookie("typpaliva", "Benzin");
}
/**********************************************/
$.ajax({
url: 'http://podivej.se/script_cas.php',
data: {druh: '30'},
type: "POST",
success: function(data){
alert($.cookie('typpaliva'));
alert($.cookie('malpg'));
}
});
});
});
</script>
HTML
<input type="checkbox" name="testcheckbox" id="uho"/>
推荐答案
使用情况:
if ($('#uho').is(':checked')) {
代替
if ($('#uho').attr('checked')) {
这篇关于jQuery是否选中了复选框Bootstrap开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文