大家好,我正在尝试运行一个函数,并在用户选择除美国以外的任何其他国家时显示一条消息。但是,我卡住了,因为我甚至不能使选择框在更改国家时记录事件。以下是我的代码:
function checkIfInternational(e) {
console.log(e);
}
const shipCountry = document.querySelector("#billing_country"); //Logs the select box
shipCountry.addEventListener("change", checkIfInternational); // listening for the change event
有什么想法,为什么会发生这种情况?是Woocommerce阻止了页面上的JS运行吗?
编辑:JS Fiddle:https://jsfiddle.net/suoc57mg/1/
const
(常量)而不是var
(变量)? - Vincenzo Di Gaetano