简体   繁体   English

ID上的文件模式弹出窗口,请点击

[英]File Modal Pop-up On ID Click

Just after some advice. 在一些建议之后。

I am trying to pop up a file modal dialog box after clicking an image. 我试图在单击图像后弹出一个文件模式对话框。 For some reason, in my browsers (IE, FF, Chrome) it doesn't seem to be working. 由于某些原因,在我的浏览器(IE,FF,Chrome)中,它似乎无法正常工作。

I have tried it in a fiddle and it seems to be working so not sure if I am doing something wrong. 我已经在小提琴中尝试过,它似乎正在工作,因此不确定我是否做错了什么。

This is what I have in the form: 这是我的形式:

<input type='file' name='photo' id='pu' class='photoupload'>
<img src='http://placehold.it/150x150' id='photo' alt='Image unavailable for $fn $ln' title='Image unavailable for $fn $ln'/>

This is what I have in the script: 这是我在脚本中拥有的:

$('#np').on('click', function()
    {
        $('#pu').click();
        console.log('Hit');
    });

I have tried it right after the document.ready function and I have also tried it with the window.load function 我已经在document.ready函数之后尝试过它,并且还使用window.load函数尝试过它

Both times it will log to the console, but for some reason it will not pop up a file modal dialog box. 两次都将登录到控制台,但是由于某种原因,它将不会弹出文件模式对话框。 Like I said, I have tried it in a fiddle and it seems to be working. 就像我说的那样,我已经在一个小提琴中尝试过了,它似乎正在起作用。 I have also tried copying it from other fiddles and it just doesn't want to work in the browsers. 我也尝试过从其他小提琴中复制它,只是不想在浏览器中使用。

Is there something simple I am missing? 有什么简单的我想念的吗?

My jQuery version is 1.9.0 with the migrate plugin 1.2.1 also. 我的jQuery版本是1.9.0,还带有移植插件1.2.1。

I just cannot figure it out. 我只是想不通。

Thanks in advance 提前致谢

Try This. 尝试这个。

$('#photo').on('click', function()    {
    $('#pu').click();      
});

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM