2011-08-26 96 views
0
<li> 
     <label>Chapter Title</label> 
     <input type="text" name="chapter[1][title]" /> 
    </li> 

    <li>  
     <label>Text</label> 
     <textarea name="chapter[1][text]" ></textarea> 
    </li> 
    <li> 
     <input type="file" name="image2" id="image2" /> 
     <img id="thumb2" width="100px" height="100px"/> 
     <input type="hidden" id="image_src2" name="chapter[1][photo]" /> 
    </li> 

    <li id="caption2" style="display:none;"> 
     <label>Photo Caption</label> 
     <input type="text" name="chapter[1][photo_caption]" /> 
    </li>  

表单字段和JavaScript代码是动态创建的。Jquery事件不适用于动态创建的html

var thumb = $('img#thumb2'); 
    new AjaxUpload('image2', { 
     action: "action", 
     name: 'userfile', 
     onSubmit: function(file, extension) { 
      $('div.preview').addClass('loading'); 
     }, 
     onComplete: function(file, response) { 
      thumb.load(function(){ 
       $('div.preview').removeClass('loading'); 
       thumb.unbind(); 
      }); 
      thumb.attr('src', response); 
      $('#image_src2').val(response); 
      $('#image_src2').live('change',function() 
      { 
       $('#caption2').show(); // this does not work 
      }); 
     } 
    });  

图像上传得很好,缩略图显示,但字幕字段没有显示,也没有显示错误。

+0

你能不能把'$( '#caption2的')显示();'代码直接跌破'$( '#image_src2')VAL(反应);'线没有把它放在里面改变功能?我这么说是因为你的'image_src2'的值无论如何都在改变,所以不需要调用另一个改变函数。 –

回答

0

试试这个你可能会绑定到change处理程序:

$('#image_src2').val(response); 
$('#caption2').show(); 
0

更改图像源后$('#image_src2').val(response)

0

尝试使用负载回调:这都将作为并显示图像时它满载

onComplete: function(file, response) { 
     thumb.load(function(){ 
      $('div.preview').removeClass('loading'); 
      thumb.unbind(); 
     }); 
     thumb.attr('src', response); 
     $('#image_src2').val(response); 
     $('#image_src2').load(function() // changed to "load" 
     { 
      $('#caption2').show(); 
     }); 
    } 
相关问题