我正在使用 JS 对输入进行一些字符限制(因为在 Shopify 上没有任何其他方法可以做到这一点)并且它在 FF 和 Chrome 中运行良好但在 Safari 中我收到以下错误:
SyntaxError: The string did not match the expected pattern.
指的是下面form:
中的定义
document.addEventListener('DOMContentLoaded', function () {
var shippingAddressEl = document.querySelector('.section--shipping-address')
if (shippingAddressEl) {
var formValidation = {
els: {
el: shippingAddressEl,
form: {
firstname: shippingAddressEl.querySelector('input[name="checkout[shipping_address][first_name]"]:not([data-honeypot="true"]'),
lastname: shippingAddressEl.querySelector('input[name="checkout[shipping_address][last_name]"]:not([data-honeypot="true"]'),
company: shippingAddressEl.querySelector('input[name="checkout[shipping_address][company]"]:not([data-honeypot="true"]'),
addressLine1: shippingAddressEl.querySelector('input[name="checkout[shipping_address][address1]"]:not([data-honeypot="true"]'),
addressLine2: shippingAddressEl.querySelector('input[name="checkout[shipping_address][address2]"]:not([data-honeypot="true"]'),
city: shippingAddressEl.querySelector('input[name="checkout[shipping_address][city]"]:not([data-honeypot="true"]'),
postcode: shippingAddressEl.querySelector('input[name="checkout[shipping_address][zip]"]:not([data-honeypot="true"]'),
phone: shippingAddressEl.querySelector('input[name="checkout[shipping_address][phone]"]:not([data-honeypot="true"]')
}
}
}
});
如何修复这个错误?
最佳答案
编辑:我发现了原因:
form
对象中的几乎每个值都缺少 )
:
城市:shippingAddressEl.querySelector('input[name="checkout[shipping_address][city]"]:not([data-honeypot="true"]'),
关于javascript - 为什么 JS 字符限制会在 Safari 中被打破?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50116845/