简体   繁体   English

应用某些CSS样式后,fileupload click事件无法正确触发(在IE 8上)

[英]fileupload click event doesnt get fired properly after applying certain css styles (On IE 8)

I have the following 我有以下

Asp.net Markup Asp.net标记

 <div class="formSample">
        <div class="uploadTest">
            Choose File 
        <asp:FileUpload ID="uploadControl" runat="server" />
        </div>          
 </div>

Class CLass CLass类

.formSample .formSample

{
   display: inline-block;
   float: right;
   width: 22em;
   margin-top: 0.3em;
}

.uploadTest .uploadTest

 {
   font-family: 'open_sansregular', Arial, Helvetica, sans-serif;
   float: right;
   overflow: hidden;
   width: 9em;
   text-align: center;
   color: white;
    font-size: 1em;
   background: #22a0db;
   cursor: pointer;
    padding: 0.4em 0.2em 0.1em 0.3em;
     margin: 0em 0em;
    border-radius: 1em;
   -webkit-border-radius: 1em;
    -moz-border-radius: 1em;
    -ms-border-radius: 1em;
    -o-border-radius: 1em;
}

Javascript 使用Javascript

    function upLoadOnClick() {
        document.getElementById('ctl00_ContentPlaceHolder1_uploadControl').parentNode.click();
    }

      document.getElementById('ctl00_ContentPlaceHolder1_uploadControl').onClick = upLoadOnClick;

The issue here is when i press the control on the right hand side then only the pop up appears but when i press the control on middle or left the browse window doesnt fire up. 这里的问题是,当我按下右侧的控件时,仅弹出窗口出现,但是当我按下中部或左侧的控件时,浏览窗口不会启动。 This problem only occurs in IE8. 仅在IE8中会出现此问题。 Any suggestions? 有什么建议么?

Thanks in advance 提前致谢

First of all, most (and probably all modern) browsers do not allow programmatic clicks of file inputs for security reasons, so your javascript will not work the way you want it to. 首先,出于安全原因,大多数(可能是所有现代)浏览器均不允许以编程方式点击file输入,因此您的JavaScript将无法正常运行。 To get the select file popup to appear the user must click the control themselves. 要使选择文件弹出窗口出现,用户必须自己单击控件。 Your code as-is without the javascript seems to work as expected for me in both Chrome and Firefox. 您的没有JavaScript的代码似乎可以在Chrome和Firefox中正常运行。 Here is a fiddle . 这是一个小提琴

The file input is notoriously difficult to style across browsers. 众所周知,跨浏览器很难设置file输入的样式。 The most common approach I believe is to make the file input invisible and overlay it on top of other elements that are styled the way you want them to look. 我认为,最常见的方法是使文件输入不可见,并将其覆盖在按您希望其外观样式设置的其他元素之上。 Here's another example fiddle . 再举一例小提琴

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

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