我在safari 9上有js的问题我的代码:
const subscribeForm = document.querySelector('#subscribeForm');
subscribeForm.addEventListener('submit', function (e) {
e.preventDefault();
fetch(this.action + '?action=subscribe&email=' + this[0].value + '&site=' +<? print $this->id_site ?>)
.then((r) => {
return r.json();
})
.then((r) => {
this.insertAdjacentHTML('afterend', `<p>${r.response}</p>`)
});
});
错误SyntaxError:意外的标记'>'
请给我一些想法在其他浏览器上都很好。
看看can I use Safari 9不支持箭头功能,请改用function() {
。在Safari 10中还添加了与template literals where added in 9.1和fetch相同的const,因为你可以使用像unfetch这样的polyfill。
所以你的代码应该是这样的:
<script src="https://unpkg.com/unfetch/polyfill"></script>
<script>
var subscribeForm = document.querySelector('#subscribeForm');
subscribeForm.addEventListener('submit', function (e) {
e.preventDefault();
fetch(this.action + '?action=subscribe&email=' + this[0].value + '&site=' +<? print $this->id_site ?>)
.then(function(r) {
return r.json();
})
.then(function(r) {
this.insertAdjacentHTML('afterend', '<p>' + r.response + '</p>');
});
});
</script>
你还需要在Safari 10中添加insertAdjacentHTML,你可以试试polyfill。