Javascript或没有按预期工作

时间:2018-04-09 22:44:04

标签: javascript sharepoint

我有一个sputility脚本,当在另一个字段中进行特定选择时,它会隐藏/显示特定字段。我需要和#34; MYPLAN"如果未在源字段中选择它,则隐藏。

我正在尝试使用||作为或声明,但它不起作用。当我不放入||代码工作正常。

<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"> 
  </script>
<script src="https:///SiteAssets/sputility.js"></script>

<script>
$(document).ready(function () {
// Get a the choice field
var choiceField = SPUtility.GetSPField('Opportunity Type');

// create a function to show or hide a field based on the selected choice 
Field value
var ShowHideField = function() {
var selectedFieldValue = choiceField.GetValue();
// Hide the 'Other Title' field if the selected value is 'Other'
if(selectedFieldValue != 'MyPlan for Monitoring' || selectedFieldValue != 
'MyPlan for Imaging') {
SPUtility.GetSPField('PCAM / CRAM Name').Hide();
SPUtility.GetSPField('Exec IT Sponsor / Title').Hide();
SPUtility.GetSPField('Exec Care Delivery Sponsor / Title').Hide();
SPUtility.GetSPField('Contract End Year').Hide();
SPUtility.GetSPField('Current Year Estimated Value ($M)').Hide();
SPUtility.GetSPField('Swat TeamEngaged').Hide();
SPUtility.GetSPField('Installed Base Documention').Hide();
SPUtility.GetSPField('SR SA and SR Clinical Consultant Engaged').Hide();
SPUtility.GetSPField('ZVP Feedback').Hide();
 }
 else {
SPUtility.GetSPField('PCAM / CRAM Name').Show();
SPUtility.GetSPField('Exec IT Sponsor / Title').Show();
SPUtility.GetSPField('Exec Care Delivery Sponsor / Title').Show();
SPUtility.GetSPField('Contract End Year').Show();
SPUtility.GetSPField('Current Year Estimated Value ($M)').Show();
SPUtility.GetSPField('Swat TeamEngaged').Show();
SPUtility.GetSPField('Installed Base Documention').Show();
SPUtility.GetSPField('SR SA and SR Clinical Consultant Engaged').Show();
SPUtility.GetSPField('ZVP Feedback').Show();

 }
 };

 // Call ShowHideField in Edit and Display form
ShowHideField();
 // attach the function to choice field
 $( choiceField.Dropdown).on('change', ShowHideField);
});
</script>

1 个答案:

答案 0 :(得分:0)

您的测试表达式,如所写,意味着

  

如果selectedFieldValue不等于&#34; MyPlan for Monitoring&#34;或者它不等于&#34; MyPlan for Imaging&#34;然后做以下......

想一想。如果 等于"MyPlan for Monitoring",则 等于"MyPlan for Imaging"。另一方面,如果它等于"MyPlan for Imaging",那么它不等于"MyPlan for Monitoring"。显然,如果它不相同,那么测试也是如此。

无论如何,||表达式的一面或另一面都是true

您想要的是&&(&#34; AND&#34;),而不是||