文件对话框未出现在jquery-ui对话框中

时间:2011-08-09 13:02:15

标签: jquery-ui file-upload jquery-ui-dialog filedialog

我有一个jquery-ui对话框,其中包含<form>,其中包含<input type=file&gt;

对于我的一些用户,当他们点击按钮打开文件对话框时:它不会出现。

问题不是基于浏览器,因为有此问题的计算机能够使用所有已安装的浏览器重现它:

  • 火狐
  • internet explorer

问题不是基于操作系统,因为我已经看到了问题的发生:

  • Windows XP
  • windows 7
  • Kubuntu 11.04

我已经安装了带有这些操作系统的虚拟机,文件对话框工作正常。

所以我的问题是:任何人都知道发生了什么事?

这是“代码”:

<meta charset="utf-8">

    <link rel="stylesheet" href="http://matchfwd-statics.s3-website-us-east-1.amazonaws.com/asset_cache/css/e1b34bd841d9.css" type="text/css" media="all"> 
    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'>

                 

    <script>

      $(function() {
         $( "#dialog-form" ).dialog({
           autoOpen: false,
           height: 500,
           width: 550,
           modal: true,
           buttons: {
             "Send": function() {
              $( this ).dialog( "close" );
           },
           Cancel: function() {
             $( this ).dialog( "close" );
           }
           },
           close: function() {
            allFields.val( "" ).removeClass( "ui-state-error" );
           } });

       $( "#create-user" ) .button() .click(function() { $( "#dialog-form" ).dialog( "open" ); });
       });
 </script>
 <div class="demo">

  <div id="dialog-form" title="Create new user">
    <p class="validateTips">All form fields are required.</p>
    <form class="main-form" method="post" action="" enctype="multipart/form-data">
        <h3>Fill in some details</h3>
        <span class="title">Your profile will be submitted with your application:</span><br/>
        <div class="holder" style="position:relative;top:12px"><a style="color:#24c2c9;" href="></a></div>
        <br>
        <span class="title">Why would you be the right candidate?</span><br/>
        <div class="holder"><textarea class="" name="description" cols="58" rows="10"> </textarea></div>
        <span class="note"></span>
        <span class="title">Attachments&nbsp;<a href="#" id="add_attachment" class="plus">&nbsp;</a></span>
        <div id="attachments" class="holder"></div>
    </form>
</div>

<button id="create-user">Create new user</button>

<script type="text/javascript">
(function() {
   var counter=1;
   $("#add_attachment").click(function(e){
   e.preventDefault();
   var attachmentString = 'attachment-'+counter
   var inputString = '<input type="file" name="'+attachmentString+'" id="id_'+attachmentString+'" />'
   $(inputString).appendTo("#attachments")
   counter = counter+1
   })})();
 </script>

2 个答案:

答案 0 :(得分:3)

我刚刚体验过这个(OSX,Chrome)并找到了您的问题。因为你没有找到答案,所以我决定做一些疯狂的事。

$(“input.file”)。live('click',function(element){element.click()});

......这实际上解决了这个问题。请注意,如果你放一个;在click()之后,它会给出一个错误,说明该元素没有click方法。

我不知道为什么会这样。这是我实施过的第二次最糟糕的黑客攻击,我为此感到羞耻。有人,请弄明白这一点,所以我不必在我的代码中留下这个丑陋,丑陋的黑客。

另请注意,我的输入有“类”文件,因此您可能需要更改选择器以满足您的需求。

答案 1 :(得分:1)

这没有任何感觉,谢谢William的解决方案。我出于某种原因无法评论你的回答。

但即使没有“;”,我仍然可以获得无点击方法。

稍后编辑 没关系,这是一个事件泡沫,让一切都搞砸了。