2011-07-15 144 views
0

我是Jquery的新手,目前正在使用Sharepoint列表。這裏有一種情況是禁用另一個單選按鈕列中選中選項的單選按鈕列。 單選按鈕column1和單選按鈕column2每個都有兩個選項。如果在單選按鈕列1中選擇了選項2,則應禁用整個單選按鈕列2。下面是我對使用jquery禁用另一個單選按鈕上的單選按鈕列

<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> 

下面工作的代碼爲頁(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> 

任何幫助或代碼的修改是非常有幫助的

親切的問候 BK

+0

您可能需要查看一些爲使用Sharepoint而創建的javascript/jquery庫。訪問Sharepoint頁面上的元素是一個巨大的痛苦。 –

回答

0

以下代碼適用於我。感謝您的所有輸入。可以建立在您提供的輸入的代碼上。

<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> 
0

如果我正確查看您的代碼,那麼您在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 

否則代碼看起來像它應該工作。

這裏的東西應該工作:

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:

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

測試在這裏: http://jsfiddle.net/jL5A5/1/

+0

這是自動生成sharepoint頁面的源代碼。我已經處理了我手上的東西。 – Bk8579

+0

如果您無法修改輸入組的名稱,請嘗試使用類或html5數據屬性,例如:

0

這裏小提琴:http://jsfiddle.net/gm5N8/

你的代碼被輕度修改,但我不得不說,你有瘋狂的名稱/ ID /值。他們很可怕。至少你有不可讀的名稱/ ID,你的值很奇怪(如ctl01ctl00)。嘿,和他們一起做點什麼。

+0

這些是自動生成的源代碼共享點頁面。我已經處理了我手上的東西。 – Bk8579

+0

我知道,嘗試將ClientID傳遞給JS,並在使用它們之後 –

相關問題