Javascript与safari的兼容性9

问题描述 投票:0回答:1

我在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:意外的标记'>'

请给我一些想法在其他浏览器上都很好。

javascript safari
1个回答
0
投票

看看can I use Safari 9不支持箭头功能,请改用function() {。在Safari 10中还添加了与template literals where added in 9.1fetch相同的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

© www.soinside.com 2019 - 2024. All rights reserved.