我正在使用Sharepoint 2010,我試圖根據當前用戶的角色隱藏不同的字段。我的代碼只適用於普通的文本字段,但它不適用於下拉列表,所以我不知道爲什麼會發生這種情況。在Sharepoint 2010中隱藏下拉列表與jquery
這裏是我的javascript代碼:
function hideColumn(c) {
$(".ms-formlabel").filter(function() {
var thisText = $.trim($(this).clone().children().remove().end().text());
return thisText.indexOf(c) === 0 && thisText.length === c.length;
}).closest("tr").hide();
}
function isGroupMember(groupName, callback){
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: true,
completefunc: function(xData, Status) {
callback(!!($(xData.responseXML).find("Group[Name='" + groupName + "']").length));
}
});
};
isGroupMember("Lectura-All", function(result){
isGroupMember("Propietarios Gobierno TI y Arquitectura Empresarial",function(resultado){
if(resultado){
hideColumn("Días Resolución Arq. Emp");
hideColumn("Días Resolución Comité Reducido");
hideColumn("Días Resolución Comité Arquitectura");
}
});
});
編輯:
這裏是我想要隱藏的HTML代碼的一部分,其他所有的領域都等於:
<tr><td width="190px" valign="top" class="ms-formlabel"><h3 class="ms-standardheader"><nobr>Días Resolución Comité Arquitectura<span class="ms-formvalidation"> *</span></nobr></h3></td><td width="400px" valign="top" class="ms-formbody"><span dir="none"><table cellpadding="0" cellspacing="1">
<tbody><tr>
<td><span title="Días Resolución Comité Arquitectura: Elegir opción"><input id="ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_DropDownButton" type="radio" name="ctl00$m$g_0250d9c7_27ba_44c9_95d4_91d31951bbe6$ff26_1$ctl00$FillInButton" value="DropDownButton" checked="checked"></span><label class="ms-hidden" for="ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_DropDownButton">Días Resolución Comité Arquitectura: Elegir opción</label><select onclick="SetChoiceOption('ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_DropDownButton')" name="ctl00$m$g_0250d9c7_27ba_44c9_95d4_91d31951bbe6$ff26_1$ctl00$DropDownChoice" id="ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_DropDownChoice" title="Días Resolución Comité Arquitectura: Lista desplegable de opciones" class="ms-RadioText">
<option selected="selected" value="7">7</option>
<option value="14">14</option>
<option value="21">21</option>
</select></td>
</tr><tr>
<td><span onclick="SetFocusOnControl('ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_ctl01')" class="ms-RadioText" title="Días Resolución Comité Arquitectura: Especifique su propio valor:"><input id="ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_FillInButton" type="radio" name="ctl00$m$g_0250d9c7_27ba_44c9_95d4_91d31951bbe6$ff26_1$ctl00$FillInButton" value="FillInButton"><label for="ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_FillInButton">Especifique su propio valor:</label></span></td>
</tr><tr>
<td> <input onclick="SetChoiceOption('ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_FillInButton')" onfocus="SetChoiceOption('ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_FillInButton')" name="ctl00$m$g_0250d9c7_27ba_44c9_95d4_91d31951bbe6$ff26_1$ctl00$ctl01" type="text" maxlength="255" id="ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff26_1_ctl00_ctl01" tabindex="-1" title="Días Resolución Comité Arquitectura : Especifique su propio valor:"></td>
</tr>
</tbody></table></span>Días Espera SLA Resolución Comité Arquitectura (para último ciclo)</td></tr>
用這個html代碼代寫作品:
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<h3 class="ms-standardheader"><nobr>Nro EPM</nobr></h3></td>
<td width="400px" valign="top" class="ms-formbody"><span dir="none">
<input name="ctl00$m$g_0250d9c7_27ba_44c9_95d4_91d31951bbe6$ff4_1$ctl00$ctl00$TextField" type="text" value="2.535" id="ctl00_m_g_0250d9c7_27ba_44c9_95d4_91d31951bbe6_ff4_1_ctl00_ctl00_TextField" title="Nro EPM" class="ms-input" size="11" style="ime-mode:inactive;">
<br>
</span>Ingresar numero de proyecto asociado a la propuesta.</td>
在此先感謝。
你發現基於標籤的文本字段?很難驗證沒有源html。它是否包含必填字段的星號? – WhiteHat
我編輯的問題 –