2012-05-08 2 views
1

작성시 업로드 할 때 항상 새로운 파일 입력을 제공하는 업로드 양식을 만들고 싶습니다. 나는 새로운 입력을 만들어이 작업을 시도했지만 한 번만 작동합니다. 당신의 도움에 대한jquery에 의해 생성 된 입력 요소에 액세스하는 방법

<head><script type="text/javascript" src="jquery-1.7.2.min.js"></script></head> 
<body><form> 
    <div id="to"></div> 
    --- 
    <div id="from"><input type="file" class="new"></div> 
</form> 
<script type="text/javascript"> 
    $('.new').change(function() { 
    $('.new').appendTo('#to').removeClass('new'); 
    $('#from').append('<input type="file" class="new">'); 
    }); 
</script> 
</body> 

감사 : 다음은 코드입니다. 모두가 잘 작동 http://jsfiddle.net/UxyMw/ 또는 http://jsfiddle.net/UxyMw/1/

:

+0

이 ('에서 #')이 $를 시도하려고 (' .attr ('유형 ','파일 ') 클래스 = "새로운">')를 추가합니다.; – pranky64

답변

1
<script type="text/javascript"> 
    $('.new').live('change',function() { 
    $('.new').appendTo('#to').removeClass('new'); 
    $('#from').append('<input type="file" class="new">'); 
    }); 
</script> 
+0

.live() 메서드는 이후 버전의 jQuery에서 단점이없는 더 나은 방법을 제공하므로 더 이상 사용하지 않는 것이 좋습니다. – nu6A

+0

http://stackoverflow.com/questions/8042576/whats-the-difference-between-jive-live-and-on – nu6A

+0

고마워요, 그게 작동합니까 – yajRs

1
<script type="text/javascript"> 
    $('.new').on('change',function() { 
    $('.new').appendTo('#to').removeClass('new'); 
    $('#from').append('<input type="file" class="new">'); 
    }); 
</script> 

사용 on

+0

이 여기에서 작동하지 않습니다 – yajRs

+0

+1 최신 jquery 라이브러리를 사용하면이 작업이 가능합니다. – coolguy

0

안녕 2 작업 데모 당신을위한

코드 :

$('.new').on("change",function() { 
    $('.new').appendTo('#to').removeClass('new'); 
    $('#from').append('<input type="file" class="new">'); 
    });​ 
관련 문제