我正在使用现成的Sharepoint 2013创建自定义列表。在NewForm.aspx上,我已在内容编辑器Web部件中创建了代码,该代码应基于另一个列值(调用/附近未命中?)显示或隐藏列。这很好。我已经根据另一列的值(称为“哪个GCC / MIG / IMT?”)复制了此函数,以执行类似的操作,但是此行不起作用。
请注意,“哪个GCC / MIG / IMT?”列是从另一个共享点列表中查找的内容。它包含大约。 90个条目。这些条目中的文本类似于以下内容(出于上下文目的,摘录了一部分):
欧洲捷克共和国-MIG
欧洲-欧盟-MIG
欧洲-欧盟-IMT-GBM
欧洲-法国-MIG
欧洲-法国-IMT-GBM
基本上,我想调整我的原始代码(有效),以便它查看“哪个GCC / MIG / IMT?”中的值。列,并且如果所选值包含字母“ IMT ”(即包含一些通配符),则显示一列“ IMT PIR”。但是,当我最终选择其中包含字符“ IMT”的值时,它仅“隐藏”该列,而不“显示”该列。
不幸的是,除了搜索各种论坛以了解通配符如何在Java中工作之外,我不太确定该去哪里。例如,我不知道我是否可以在同一脚本中具有多个功能。这可能吗?
因此以下功能可以正常工作:
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript""></script><script type="text/javascript">
$(document).ready(function(){
// hide various columns when selecting "Near Miss" value
$("select[title='Invocation / Near Miss?']").change(function() {
if ($("select[title='Invocation / Near Miss?']").val() == "Near Miss") {
$('nobr:contains("Date of first IM meeting")').closest('tr').hide();
$('nobr:contains("Date of last IM meeting")').closest('tr').hide();
$('nobr:contains("Number of meetings?")').closest('tr').hide();
$('nobr:contains("PIR Author")').closest('tr').hide();
$('nobr:contains("PIR Approval Date")').closest('tr').hide();
$('nobr:contains("PIR Submitted to Corporate Security Site?")').closest('tr').hide();
$('nobr:contains("HELIOS Event ID")').closest('tr').hide();
$('nobr:contains("Incident status")').closest('tr').hide();
$('nobr:contains("PIR attached?")').closest('tr').hide();
$('nobr:contains("Incident date (near miss)")').closest('tr').show();
}
// Show certain columns when selecting "Invocation"
else if($("select[title=' Invocation / Near Miss?']").val() !== "Invocation"){
$('nobr:contains("Date of first IM meeting")').closest('tr').show();
$('nobr:contains("Date of last IM meeting")').closest('tr').show();
$('nobr:contains("PIR Author")').closest('tr').show();
$('nobr:contains("PIR Approval Date")').closest('tr').show();
$('nobr:contains("PIR Submitted to Corporate Security Site?")').closest('tr').show();
$('nobr:contains("HELIOS Event ID ")').closest('tr').show();
$('nobr:contains("Number of meetings?")').closest('tr').show();
$('nobr:contains("HELIOS Event ID")').closest('tr').show();
$('nobr:contains("Incident status")').closest('tr').show();
$('nobr:contains("PIR attached?")').closest('tr').show();
$('nobr:contains("Incident date (near miss)")').closest('tr').hide();
}
});
});
下一个函数(在相同的CEWP中编码)仅隐藏IMT PIR列,但是无论我选择哪个值,并且如果我选择一个值中包含“ IMT”的值,都不会再次显示它。
$(document).ready(function(){
// Show IMT PIR column when selecting a value which has "IMT" in it"
$("select[title='Which GCC / MIG / IMT?']").change(function() {
if ($("select[title='Which GCC / MIG / IMT?']").val() == "*IMT*") {
$('nobr:contains("IMT PIR")').closest('tr').show();
}
// Hide IMT PIR column when NOT selecting a value which has "IMT" in it"
else if($("select[title='Which GCC / MIG / IMT?']").val() !== "*IMT*"){
$('nobr:contains("IMT PIR")').closest('tr').hide();
}
});
});
</script>
从本质上讲,当“哪个GCC / MIG / IMT”中的值为某个值时,我希望看到IMT PIR列以黄色突出显示。列中的值包含“ IMT”;被选中。
请注意,我不是开发人员,但非常感谢您提供的指导:)
答案 0 :(得分:0)
使用$(this)关键字,因为您已经在change函数中。
$(document).ready(function(){
// Show IMT PIR column when selecting a value which has "IMT" in it"
$("select[title='Which GCC / MIG / IMT?']").change(function() {
if ($(this).val() == "*IMT*") {
$('nobr:contains("IMT PIR")').closest('tr').show();
}
// Hide IMT PIR column when NOT selecting a value which has "IMT" in it"
else if($(this).val() !== "*IMT*"){
$('nobr:contains("IMT PIR")').closest('tr').hide();
}
});
});