简体   繁体   English

使用 jquery 禁用另一个单选按钮上的单选按钮列

[英]Disable radio button column on another Radio button using jquery

I am new to Jquery,currently working with Sharepoint lists.我是 Jquery 的新手,目前正在使用 Sharepoint 列表。 Here having a situation to disable a radio button column with option selected in another Radio button column.这里有一种情况是禁用一个单选按钮列,并在另一个单选按钮列中选择了选项。 Radio button column1 and Radio button column2 has to two options each.单选按钮 column1 和单选按钮 column2 各有两个选项。 If option 2 selected in Radio button column1 the entire radio button column2 should be disabled.如果在单选按钮 column1 中选择了选项 2,则应禁用整个单选按钮 column2。 Below is the code I am working on下面是我正在处理的代码

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
    </script>
    <script language="JavaScript">
$(document).ready(function() 
{
 $('input[name=Who will be developing the propose site?]').change(function(){
        if($(this).val() == 'Site Adminstrator')
        {
            $('input[name=Has site administrator attest to development operations of Rules of Road]').prop('disabled',true);
        }
        else
        {
            $('input[name=Has site administrator attest to development operations of Rules of Road]').prop('disabled',false);
        }
    });
    });
    </script>

Below is the SharePoint source code for the page (SharePoint list)以下是页面的 SharePoint 源代码(SharePoint 列表)

<TR><TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
            <nobr>Who will be developing the propose site?</nobr>
        </H3></TD>
            <TD valign="top" class="ms-formbody" width="400px">
            <!-- FieldName="Who will be developing the propose site?"
                 FieldInternalName="Who_x0020_will_x0020_be_x0020_de"
                 FieldType="SPFieldChoice"
              -->
                <span dir="none"><table cellpadding="0" cellspacing="1">
        <tr>
            <td><span class="ms-RadioText" title="CSMS"><input id="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_7d3ef79b_83fe_4a1f_a469_42a8746f064e$ctl00$ctl04$ctl07$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" checked="checked" /><label for="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl00">CSMS</label></span></td>
        </tr><tr>
            <td><span class="ms-RadioText" title="Site Administrator"><input id="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_7d3ef79b_83fe_4a1f_a469_42a8746f064e$ctl00$ctl04$ctl07$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" /><label for="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl01">Site Administrator</label></span></td>
        </tr>
    </table></span></TD></TR>

            <TR><TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
            <nobr>Has site administrator attest to development operations of Rules of Road</nobr>
        </H3></TD>
            <TD valign="top" class="ms-formbody" width="400px">
            <!-- FieldName="Has site administrator attest to development operations of Rules of Road"
                 FieldInternalName="Has_x0020_site_x0020_administrat"
                 FieldType="SPFieldChoice"
              -->
                <span dir="none"><table cellpadding="0" cellspacing="1">
        <tr>
            <td><span class="ms-RadioText" title="Yes"><input id="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_7d3ef79b_83fe_4a1f_a469_42a8746f064e$ctl00$ctl04$ctl08$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" checked="checked" /><label for="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00">Yes</label></span></td>
        </tr><tr>
            <td><span class="ms-RadioText" title="No"><input id="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_7d3ef79b_83fe_4a1f_a469_42a8746f064e$ctl00$ctl04$ctl08$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" /><label for="ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl01">No</label></span></td>
        </tr>
    </table></span></TD></TR>

Any help or modifications in code are highly helpful代码中的任何帮助或修改都非常有帮助

Kind Regards BK亲切的问候 BK

Here the fiddle: http://jsfiddle.net/gm5N8/这里的小提琴: http://jsfiddle.net/gm5N8/

Your code was lightly modified but i have to say that you have crazy names/ids/values.您的代码稍作修改,但我不得不说您有疯狂的名称/ID/值。 They are terrible.他们很可怕。 At least you have non-readable names/ids and your values are very strange (like ctl01 or ctl00 ).至少您有不可读的名称/ID,并且您的值非常奇怪(例如ctl01ctl00 )。 Hey, make something with them.嘿,和他们一起做点什么。

If I'm looking at your code correctly the names you're using in jquery don't match the sharepoint autogenerated names for the inputs.如果我正确查看您的代码,则您在 jquery 中使用的名称与输入的 sharepoint 自动生成的名称不匹配。

Who will be developing the propose site?

vs对比

ctl00$m$g_7d3ef79b_83fe_4a1f_a469_42a8746f064e$ctl00$ctl04$ctl07$ctl00$ctl00$ctl04$ctl00$RadioButtons

Otherwise the code looks like it should work.否则代码看起来应该可以工作。

Here's something that should work:这是应该起作用的东西:

HTML: HTML:

<TR><TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Who will be developing the propose site?</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Who will be developing the propose site?"
             FieldInternalName="Who_x0020_will_x0020_be_x0020_de"
             FieldType="SPFieldChoice"
          -->
            <span dir="none"><table cellpadding="0" cellspacing="1">
    <tr>
        <td><span class="ms-RadioText" title="CSMS"><input id="g1button1" type="radio" name="group1" value="CSMS" checked="checked" /><label for="g1button1">CSMS</label></span></td>
    </tr><tr>
        <td><span class="ms-RadioText" title="Site Administrator"><input id="g1button2" type="radio" name="group1" value="Site Adminstrator" /><label for="g1button1">Site Administrator</label></span></td>
    </tr>
</table></span></TD></TR>

        <TR><TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Has site administrator attest to development operations of Rules of Road</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Has site administrator attest to development operations of Rules of Road"
             FieldInternalName="Has_x0020_site_x0020_administrat"
             FieldType="SPFieldChoice"
          -->
            <span dir="none"><table cellpadding="0" cellspacing="1">
    <tr>
        <td><span class="ms-RadioText" title="Yes"><input id="g2button3" type="radio" name="group2" value="ctl00" checked="checked" /><label for="g2button3">Yes</label></span></td>
    </tr><tr>
        <td><span class="ms-RadioText" title="No"><input id="g2button2" type="radio" name="group2" value="ctl01" /><label for="g2button2">No</label></span></td>
    </tr>
</table></span></TD></TR>

Jquery: Jquery:

$('input[name=group1]').change(function()
{
    if($(this).val() == 'Site Adminstrator')
    {
        $('input[name=group2]').prop('disabled',true);
    }
    else
    {
        $('input[name=group2]').prop('disabled',false);
    }
});

Test it here: http://jsfiddle.net/jL5A5/1/在这里测试它: http://jsfiddle.net/jL5A5/1/

The below code worked for me.下面的代码对我有用。 Thanks for all your inputs.感谢您的所有投入。 could able built on the code for the inputs you provided.可以建立在您提供的输入的代码上。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
    </script>
    <script language="JavaScript">
    $(document).ready(function()
    {
    $('#ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00').attr('disabled', 'disabled');
    $('#ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl01').attr('disabled', 'disabled');
    OnTypeNotificationChange();
     function OnTypeNotificationChange()
    {             
    $('input[name=ctl00$m$g_7d3ef79b_83fe_4a1f_a469_42a8746f064e$ctl00$ctl04$ctl07$ctl00$ctl00$ctl04$ctl00$RadioButtons]').click(function(){

    if($(this).val() == "ctl00")
        {
    $('#ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00').attr('disabled', 'disabled');
    $('#ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl01').attr('disabled', 'disabled');
        }
        else
        {
    $('#ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00').removeAttr('disabled');
    $('#ctl00_m_g_7d3ef79b_83fe_4a1f_a469_42a8746f064e_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl01').removeAttr('disabled');
        }
    });
      }
    });</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM