我正在创建一个自定义的共享点列表,并为隐藏/显示/清除数据输入字段,下拉列表和日期编写了一些jQuery逻辑。我需要将下拉菜单更改为单选按钮,以是/否,并且我不知道如何更改jQuery逻辑中的if语句,因此我写了目标单选按钮并检查它们的值。 / p>
有人知道我可以用jquery定位单选按钮组并获取其值吗?
我试图用
定位他们 if($("input[title='Did the Rep call a TM prior to start of shift or leaving for the day?']:checked").val() == "No")
-无效。
$("input[title='Did the Rep call a TM prior to start of shift or leaving for the day?']:checked").change(function() {
if ($("input[title='Did the Rep call a TM prior to start of shift or leaving for the day?']:checked").val() == "No"){
// *******************************Show accountability created? question***********************************
$('nobr:contains("Accountability discussion created?")').closest('tr').show();
// *******************************Reset values from previous "Yes" selection*****************************
$("select[title='Did the Rep report there was an issue with MyWorkLife?']").val("Select Yes or No");
$("select[title='Did the rep send screenshots?']").val("Select Yes or No");
// *******************************Hide questions from previous "Yes" selection***************************
$('nobr:contains("Did the Rep report there was an issue with MyWorkLife?")').closest('tr').hide();
$('nobr:contains("Did the rep send screenshots?")').closest('tr').hide();
}
}```
I expect these different rows in the table to either be shown or hidden when the if statement is met - this is only partial code there is "else if" and "else" statements after but didn't think necessary to paste it all.
答案 0 :(得分:0)
由于您已经在change函数中使用,并以if状态使用$(this)来定位同一复选框。 还要使用单引号和三等号。
$("input[title='Did the Rep call a TM prior to start of shift or leaving for the day?']:checked").change(function() {
if ($(this).val() === 'No'){
// *******************************Show accountability created? question***********************************
$('nobr:contains("Accountability discussion created?")').closest('tr').show();
// *******************************Reset values from previous "Yes" selection*****************************
$("select[title='Did the Rep report there was an issue with MyWorkLife?']").val("Select Yes or No");
$("select[title='Did the rep send screenshots?']").val("Select Yes or No");
// *******************************Hide questions from previous "Yes" selection***************************
$('nobr:contains("Did the Rep report there was an issue with MyWorkLife?")').closest('tr').hide();
$('nobr:contains("Did the rep send screenshots?")').closest('tr').hide();
}
}```