【问题标题】:How can I check a group of radio buttons value for an if statement in sharepoint?如何检查 sharepoint 中 if 语句的一组单选按钮值?
【发布时间】:2019-05-04 02:48:02
【问题描述】:

我正在创建一个自定义 sharepoint 列表,并为 隐藏/显示/清除 数据输入字段、下拉列表和日期编写了一些 jQuery 逻辑。我需要将下拉菜单更改为 yes/no 的单选按钮,但我无法弄清楚如何在 jQuery 逻辑中更改我的 if 语句,我写的是针对单选按钮并检查它们的值。

有谁知道我可以用 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.

【问题讨论】:

    标签: jquery sharepoint radio-button


    【解决方案1】:

    由于您已经处于更改功能中,因此请使用带有 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();
    
    
       }
    }```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-21
      • 2022-07-20
      • 2015-09-17
      • 1970-01-01
      • 2011-10-04
      • 2021-02-09
      • 2021-07-03
      • 2012-11-21
      相关资源
      最近更新 更多