欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

安卓版微信 input onchange (jquery change )事件不生效 微信 浏览器 不支持 input file change事件 有大用 有大大用 有大大大用 有大大大大用

做Vue 图片上传控件,遇到无法上传的问题,表现未选择图片后无法触发change事,问题原因最终锁定在input accept上。

<input type="file" accept="image/gif, image/jpeg"  onchange="fileChange">


上面的定义,在某些安卓版微信上不会触发change事件,需要改成下面形式

<input type="file" accept="image/*"  onchange="fileChange">


困扰了很久

来自 https://blog.csdn.net/nabywe/article/details/79068470



安卓 微信 input file change无效 调试

最近公司在做一个活动需要做一个网站,还需要移动端能访问。

有个上传图片的功能在andriod微信里面没有反应,而在QQ和普通浏览器都是正常的。

顿时就无语了,想着手机web怎么调试呢?于是在网上找到了AlloyLever(http://alloyteam.github.io/AlloyLever/)。

一、alloylever的安装和使用

1、alloylever安装

npm install alloylever

2、引入alloy-leve.js

<script src="/themes/js/alloy-leve.js"></script>

3、添加配置

复制代码
<script>

AlloyLever.config({
        cdn:'//s.url.cn/qqun/qun/qqweb/m/qun/confession/js/vconsole.min.js',
        reportUrl: "//a.qq.com",
        reportPrefix: 'abc',
        reportKey: 'msg',
        otherReport: {
            uin: 100000
        },
        entry:"#entry"
    })

</script>

//AlloyLever会监听window.onerror并把错误信息保存下来,并且上报到reportUrl,你也可以召唤到vConsole并显示出来错误和相关日志。
复制代码


4、url唤起vConsole

只要你的页面引用了AlloyLever,你只需要在你的url里带上 vconsole=show 就能显示vConsole面板。如:

http://localhost:63342/AlloyLever/index.html?vconsole=show

 

经过调试发现是input绑定的change事件无效。

<input id="fileImage" type="file" accept="image/*"/>

后经查询需要加上capture="camera"属性。

<input id="fileImage" type="file" accept="image/*;capture=camera"/>

经过测试,正常了!!!


来自  https://www.cnblogs.com/java-chanjuan/p/8038296.html



4个回答

0

是不是选中之后,再选相同的文件,change就不触发?你可以在你执行完操作之后,把input的值清空,这样选相同的文件,能再次触发。

0
  • change 事件被<input>, <select>, 和<textarea> 元素触发, 当用户提交对元素值的更改时。与 input 事件不同,change 事件不一定会对元素值的每次更改触发。

  • 当 <input> 或 <textarea> 元素的值更改时,DOM input 事件会同步触发
    ps:建议你把demo贴上来




来自  https://segmentfault.com/q/1010000008956433


普通分类: