3

So, i am using a bootstrap modal, and inside of the modal, i want to use image upload, but when an image is selected, nothing happens, i am asuming it is a javascript issue, the script and the css is included outside of标头中的模态。

http://jasny.github.com/bootstrap/javascript.html#fileupload

有什么建议么?我认为这是一个javascript问题

<?php 
if (isset($_SESSION['login']) and !empty($_SESSION['login']) and $_SESSION['rank'] == 3) {


echo '
    <!-- Modal -->
    <div id="insert_post_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
       <div class="modal-header">
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
       <h3 id="myModalLabel">Insert Post</h3>
      </div>
      <div class="modal-body">
      <p>

    <form action="insert_post_sql" method="post" enctype="multipart/form-data">

        <table border="0">


<div class="fileupload fileupload-new" data-provides="fileupload">
    <div class="fileupload-new thumbnail" style="width: 200px; height: 150px;"><img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+image" />
    </div>
<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;">
    </div>
<div>
    <span class="btn btn-file"><span class="fileupload-new">Select image</span>
        <span class="fileupload-exists">Change</span><input type="file" /></span>
        <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>
          </table>
     </form>

     </p>
     </div>
     <div class="modal-footer">
     <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
     <input type="submit" button class="btn btn-primary" value="Submit Post">
     </div>
   </div>
   </form>
   ';
}
?>
4

2 回答 2

2

尝试使用Document Ready 功能,因为脚本是在模态 HTML 之前加载的

 $('document').ready(function(){
        $('#insert_post_modal').on('shown', function(){

           $('.fileupload').fileupload();

        }); 

    });
于 2013-03-15T19:46:17.837 回答
0

尝试在显示的模式上调用文件上传(即当用户打开它时):

$('#insert_post_modal').on('shown', function(){

   $('.fileupload').fileupload();

});

不过现在不能测试,对不起

于 2013-03-15T19:35:38.083 回答