2011-08-26 3 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>  

양식 필드와 자바 스크립트 코드가 동적으로 생성됩니다.동적으로 생성 된 html에서 Jquery 이벤트가 작동하지 않습니다.

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

당신이 ('#의 이름 2')은'$를 넣어 수 없습니다로드 쇼(). '코드를 직접'$ 이하 ('#의 image_src2 ')를 발 (응답).'라인 안에 넣지 않고 변경 기능? 나는 당신의'image_src2's' 값이 어쨌든 변화하므로 다른 변경 기능을 부를 필요가 없기 때문에 이것을 말하고 있습니다. –

답변

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(); 
     }); 
    } 
관련 문제