简体   繁体   English

jQuery插件断开只是因为我删除了'.css({display:'none'})'

[英]jquery plugin breaking just because I remove '.css({display: 'none'})'

I'm using a jquery plugin which replaces the file input of a form with a div, so when you click the div the file browser pops up. 我使用的是一个jQuery插件,该插件用div替换了表单的文件输入,因此,当您单击div时,将弹出文件浏览器。 When you select a file the form gets submitted automatically and the results go into a hidden iframe. 选择文件后,表单会自动提交,结果进入隐藏的iframe。 The idea behind all this is that you can just have an image saying 'click to upload' and with one click a file browser appears and when you select the file it uploads behind the scenes. 所有这些背后的想法是,您可以只显示一个图片,上面写着“单击以上传”,然后单击一下就会出现文件浏览器,并且当您选择文件时,它会在后台上传。

Anyway, I know that there's problems happening in my php when the file submits, but because the results get loaded into a hidden iframe I can't see what the errors are! 无论如何,我知道在文件提交时我的php中发生了问题,但是由于结果被加载到隐藏的iframe中,所以我看不到错误是什么!

So obviously remove the hidden style from the iframe, but the problem is the plugin adds the display:hidden in the javascript of the plugin. 因此显然可以从iframe中删除隐藏的样式,但是问题是插件在插件的javascript中添加了display:hidden。 It does: 它确实:

var iframe = $(
        '<iframe '+
            'id="iframe'+id+'" '+
            'name="iframe'+id+'"'+
        '></iframe>'
    ).css({
        display: 'none'
    });

However, if I remove the: 但是,如果我删除:

.css({
        display: 'none'
    });

bit, then the whole thing seems to break in that clicking on the image with 'click to upload' no longer brings the file browser up. 一点,然后整个事情似乎中断了,即单击“单击上传”单击图像不再使文件浏览器启动。

The plugin javascript isn't long but probably too long to post in here but you can look at it here: http://liquidlizard.net/jquery.ocupload.js if anyone can help me out it'd be great! 插件javascript时间不长,但可能太长了,无法在此处发布,但是您可以在这里查看: http : //liquidlizard.net/jquery.ocupload.js如果有人可以帮助我,那太好了!

How come removing just that css() function stops the whole thing from working? 为什么只删除css()函数会阻止整个工作? Is there another way to see the contents of the hidden iframe? 还有其他方法可以查看隐藏的iframe的内容吗?

EDIT Here's a jsfiddle as suggested in the comments. 编辑这是注释中建议的jsfiddle。 http://jsfiddle.net/VF6Qb/ In the javascript starting at line 35 if you remove the .css({display:'none'}); http://jsfiddle.net/VF6Qb/如果您删除了.css({display:'none'});在第35行开始的javascript中; then clicking the div will no longer open the file browser dialog box 然后单击div将不再打开文件浏览器对话框

When you're removing the display:none; 卸下display:none; , the <iframe> is somehow overlapping the file input and the clicked div so it won't trigger the file browser. <iframe>以某种方式使文件输入和单击的div重叠,因此不会触发文件浏览器。 You can test this fiddle where I've swapped the iframe's and submit-form's DOM positions, and voila - it works. 您可以测试这个小提琴 ,我已经换了iframe的,并提交形式的DOM位置,瞧-它的作品。

However, for just inspecting the error document in the iframe you would not make the iframe visible, but just inspect its source code (and HTTP headers) in FireBug's net panel . 但是,仅检查iframe中的错误文档就不会使iframe可见,而只是在FireBug的net面板中检查其源代码(和HTTP标头)。

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

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