gpt4 book ai didi

javascript - 如何使用 JavaScript 中的 this.value 从下拉列表中检查特定值

转载 作者:行者123 更新时间:2023-11-28 17:02:20 25 4
gpt4 key购买 nike

我有一个下拉选择列表,其中包含大约 10 个选项,这些选项与一个隐藏的 div 连接,当使用 javascript 代码仅选择 3 个特定选项中的任何一个时,应该显示该隐藏的 div

document.getElementById('item').addEventListener('change', function () {
var style = (this.value == "661056067" or this.value == "571855424") ?
'table-row' : 'none';
document.getElementById('hidden_div').style.display = style;
});

我尝试了上面显示的代码,因为我希望 this.value 函数等于多个值,但它不起作用。那么什么是让 ot 工作的正确方法呢?请注意,我对 javascript 一点也不擅长。感谢您的帮助

最佳答案

使用||代替

document.getElementById('item').addEventListener('change', function () {
var style = (this.value == "661056067" || this.value == "571855424") ?
'table-row' : 'none';
document.getElementById('hidden_div').style.display = style;
});

您还可以使用包含

document.getElementById('item').addEventListener('change', function () {
var style = ["661056067", "571855424"].includes(this.value) ? 'table-row' : 'none';
document.getElementById('hidden_div').style.display = style;
});

关于javascript - 如何使用 JavaScript 中的 this.value 从下拉列表中检查特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57011908/

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