# 华为自带浏览器点击事件无效

**URL:** <https://www.shiqidu.com/t/topic/441>\
**Category:** 开发调优\
**Tags:** JavaScript\
**Created:** [2018 年6 月 14 日 09:43 UTC](https://www.shiqidu.com/t/topic/441 "2018-06-14T09:43:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2018 年6 月 14 日 09:43 UTC](https://www.shiqidu.com/t/topic/441/1 "2018-06-14T09:43:56Z")

</div>

一段非常简单的js，给一个dom元素绑定点击事件。

```javascript
$(document).on('click', '.send-sms-code', function(){
    ...
    $.ajax({
        ...
    })
})

```

在safari、oppo、小米自带的浏览器中都测试过没问题，但是在华为自带浏览器中，点击事件无效。

后查明原因是因为语法兼容的问题

```javascript
$(document).on('click', '.send-sms-code', function(){
    let mobile = $('input[name="mobile"]').val();
    if (...) {
        $.ajax({
            ...
        })
    }
})

```

大华为浏览器不支持用`let`关键字声明变量，只能使用`var`。

---

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2018 年6 月 14 日 09:50 UTC](https://www.shiqidu.com/t/topic/441/2 "2018-06-14T09:50:58Z")

</div>

附上检查浏览器是否支持es6的工具链接[http://ruanyf.github.io/es-checker/index.cn.html](http://ruanyf.github.io/es-checker/index.cn.html)
