如果选择了 2 个选项中的任何一个,则 Greasemonkey 脚本会更改下拉选项

Greasemonkey Script to change drop down option if either of 2 options are selected

所以,我有一个接受值的表单,并在提交时将值附加到多个选项卡中的另一个表单。

如果用户选择 IT 或 ES,我正在尝试 select 下拉菜单的第二个选项。

这是我的油猴:

var taxcty = document.getElementById("CountryCode");
if (taxcty.options[taxcty.selectedIndex].value == 'IT' || 'ES'){

  (document.querySelector && document.querySelector('select[name="currentState"]') || []).value = 'Unverified';
}

所以理论上,如果用户select的"CountryCode"字段中的IT或ES,我希望currentState字段变为"Unverified"。

它现在部分工作,但它也正在将所有其他国家/地区代码更改为未验证哈哈。因此,如果我选择 "GB",它实际上会更改为未验证,但我只希望它为 IT 或 ES 执行此操作。

if (taxcty.options[taxcty.selectedIndex].value == 'IT' || taxcty.options[taxcty.selectedIndex].value == 'ES'){

您需要对所有值进行比较的两边。 'ES' 作为一个独立的操作数将始终为真,因为它不是空的、空的或假的。