[英]javascript compatibility chrome, safari, and opera on string search
[英]Javascript compatibility with safari 9
我在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>`)
});
});
错误语法错误:意外令牌'>'
请给我一些想法,在其他浏览器上都很好。
看一下我可以使用 Safari 9不支持箭头功能,而是使用function() {
代替。 在9.1中与fetch和const相同的模板文字也已在Safari 10中添加,对于fetch,您可以像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 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.