jQuery选中刷新和唯一值查询复选框 [英] jquery checked checkbox on refresh and unique value query
本文介绍了jQuery选中刷新和唯一值查询复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅在刷新时使用正确的值检查了checkbox
时,我才尝试运行一段代码?
I'm trying to run a piece of code only when a checkbox
is checked on refresh with the correct value?
if ($("input[name='business_group']").attr("checked")==true && .val("accommodation")) {
$(".acc_title").show();
$(".fd_title").hide();
$(".dest_title").hide();
$(".ttt_title").hide();
$(".c_name_container").show();
$(".stay").show();
$(".visit").hide();
alert("accommodation checked");
}
else if ($("input[name='business_group']").attr("checked")==true && .val("food_drink")) {
$(".fd_title").show();
$(".acc_title").hide();
$(".dest_title").hide();
$(".ttt_title").hide();
$(".c_name_container").show();
$(".stay").hide();
$(".visit").show();
alert("food_drink checked");
}
您知道上面的代码为什么不起作用吗?
Any idea why the above code doesn't work?
推荐答案
您的jQuery代码略有错误,这应该可以执行您想要的操作:
You jQuery code is slightly wrong, this should do what you want:
if ($("input[name='business_group']:checked").val() === "accommodation") {
// code here
} else if ($("input[name='business_group']:checked").val() === "food_drink") {
// code here
}
事实上,最好将此值保存到变量中:
Infact it would be better to save this value into a variable:
var checkedValue = $("input[name='business_group']:checked").val();
switch(checkedValue) {
case "accommodation": // do stuff; break;
case "food_drink": // do other stuff; break;
}
这篇关于jQuery选中刷新和唯一值查询复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文