gpt4 book ai didi

javascript - 有条件地隐藏类(class)

转载 作者:行者123 更新时间:2023-11-30 17:03:55 26 4
gpt4 key购买 nike

我是 jQuery 的新手,我一直在努力完成以下任务:

我在 SharePoint 2013 中有两个下拉菜单。当在 Role 菜单中选择 WFE 值时,我希望 Environment 字段消失。

我无法验证是否选择了 WFE:

$().ready(function () {
$('.Role').change(function () {
if ($('.Role').val() = 'WFE') {
$('.Environment').hide();
alert('Changed!');
}
});
});

<table cellpadding="5" cellspacing="5" bgcolor="black" >
<tr >
<td>
<!--Environment is a drop down menu in SharePoint 2013---->
<b>Environment</b><br>
<span class="Fields Environment" data-displayName="Environment"></span>
</td>

</tr>
<tr >
<td>
<!--Role is a drop down menu in SharePoint 2013---->
<b>Role</b><br>
<span class="Fields Role" data-displayName="Role"></span>
</td>
</tr>
</table>

我看了好几篇文章,一点线索也没有。感谢您的建议。

最佳答案

$('.Role').val() = 'WFE'

应该是

$('.Role').val() === 'WFE'

= 表示赋值,=== 表示严格的类型和值相等,这几乎总是您想要的! == 可以使用,但会咬你,因为它会进行静默隐式转换,这会引入很难发现的细微错误。显式总是比隐式好。

JavaScript Comparison Operators

JavaScript has both strict and type–converting comparisons. A strict comparison (e.g., ===) is only true if the operands are of the same type. The more commonly used abstract comparison (e.g. ==) converts the operands to the same Type before making the comparison. For relational abstract comparisons (e.g., <=), the operands are first converted to primitives, then to the same type, before comparison.

Strings are compared based on standard lexicographical ordering, using Unicode values.

关于javascript - 有条件地隐藏类(class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28373065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com