因此,我有一个接受值的表单,并在提交时将值附加到多个选项卡中的另一个表单。
如果用户选择 IT 或 ES,我将尝试选择下拉列表的第二个选项。
这是我的油猴:
var taxcty = document.getElementById("CountryCode");
if (taxcty.options[taxcty.selectedIndex].value == 'IT' || 'ES'){
(document.querySelector && document.querySelector('select[name="currentState"]') || []).value = 'Unverified';
}
所以理论上,如果用户在“CountryCode”字段中选择IT或ES,我希望currentState字段更改为“Unverified”。
它现在部分工作,但它也将所有其他国家/地区代码更改为未经验证哈哈。因此,如果我选择“GB”,它实际上会更改为“未验证”,但我只希望它为 IT 或 ES 执行此操作。
最佳答案
if (taxcty.options[taxcty.selectedIndex].value == 'IT' || taxcty.options[taxcty.selectedIndex].value == 'ES'){
您需要对所有值进行比较的双方。 'ES' 作为独立操作数将始终为 true,因为它不为 null、空或 false。
关于javascript - 如果选择了两个选项之一,则 Greasemonkey 脚本可更改下拉选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46342811/