在WooCommerce结账过程中,当账单国家发生更改时运行JavaScript代码。

5 浏览
0 Comments

在WooCommerce结账过程中,当账单国家发生更改时运行JavaScript代码。

大家好,我正在尝试运行一个函数,并在用户选择除美国以外的任何其他国家时显示一条消息。然而,我被卡住了,因为我甚至无法让选择框在更改国家时记录事件。这是我的代码:

function checkIfInternational(e) {
  console.log(e);
}
const shipCountry = document.querySelector("#billing_country"); //记录选择框
shipCountry.addEventListener("change", checkIfInternational); //监听change事件

有什么想法吗?是Woocommerce阻止了JS在页面上运行,还是其他什么原因?

编辑:JS Fiddle:https://jsfiddle.net/suoc57mg/1/

0