如何防止在使用jquery的浏览中看不到任何图像 [英] How to prevent none images to be seen in browsing using jquery

查看:161
本文介绍了如何防止在使用jquery的浏览中看不到任何图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是,如果用户点击浏览文件,他应该看到的图像只有没有其他文件。如何使用 jquery

I want to do is if the user click to browse for files he should see images only no other files. How to do that using jquery?

我的问题是,我可以看到和选择其他文件,除了图像,当我浏览。

My problem is I can see and choose other files besides images when i browse.

当前输出: http://jsfiddle.net/ LvsYc / 3123 /

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#Picture').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#imgInp").change(function(){
    readURL(this);
});


推荐答案

将输入内容更改为:

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

http://jsfiddle.net/LvsYc/3124/

这篇关于如何防止在使用jquery的浏览中看不到任何图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆