2014-03-24 3 views
1

저는 HTML 블록을 복제 한 다음 양식에 추가하고 있습니다. .clone 다음에 라디오 버튼이 작동하지 않습니다.복제 후 유니폼 라디오가 작동하지 않습니다.

예 : http://jsfiddle.net/JNCFP/169/

HTML :

<form> 
    <div class="formElement"> 
     <input type="radio" name="radio" /> 
     <input type="text" name="text[]" /> 
     <button class="button" type="button">Clone</button> 
    </div> 
</form> 

자바 스크립트 :

$(function() { 
    // Uniform every form element 
    $('input, select').uniform(); 

    // clone Div 
    $('form .button').click(function() { 
     var el = $(this).parents('.formElement'); 
     $(el).clone(true).insertAfter($(el)); 
    }); 
}); 
당신은 그것을 새로운 요소 플러그인을 초기화 할 수 있도록 당신이 그것을 복제 후 다시 .uniform()를 호출 할 필요가
+2

"작동하지 않음"을 정의하십시오. 네가하고 싶지 않은게 뭐지? –

+0

복제 된 라디오 버튼을 선택할 수 없습니다. 유니폼을 사용하지 않으면 모든 것이 잘됩니다. – nburgic

답변

2

:

// Uniform every form element 
$(function() { 
    // Show browser information 
    $('input, select').uniform(); 

    $('form').on('click', '.button', function() { 
     var el = $(this).parents('.formElement'); 
     $(el).clone().insertAfter($(el)); 
     $('input, select').uniform(); 
    }); 

}); 

Fiddle

+0

예, 작동하지만'withDataAndEvents'를 true로 설정하지 않고 복제하면 '

+0

또한'click' 이벤트를 다시 바인딩해야합니다. 대신 이벤트 위임을 제안합니다. 답변이 포함되어 업데이트되었습니다. 그 버튼들은 모두 작동해야합니다. –

관련 문제