내가 업로드 양식을 만들려고 해요. 그것은 지금까지 잘 작동하고 그리고 난 내가 싫어하는 버그의 몇 가지를 분류하는 것을 시도하고있다.복제 폼 입력하고 명확한 값
$(element).find(">:first-child").attr("value", "");
이다와 나는 것
선은 형태를 복제 할 때, 내가한다면이 잘 작동 사업부 클론 아무것도 빈 양식을 남기지 않고와 값을 대체하는 데 문제가있다 나는 이전 폼의 값을 얻을 것이라고 줄을 삭제, 그래서 빈 양식을 표시하는 것이 좋을 것이다. 당신은 모든 형태의 값이 삭제 양식을 삭제하면
난 데 문제는, 내가 원하는 무엇을, 양식을 삭제 다른 형태 혼자 값을 떠날 때입니다.
가 여기에 바이올린 http://jsfiddle.net/d77pd/1/ 나
HTML 아래 코드를 볼 수
<button class="clone">Add an Image</button>
<div id="upload_image_sets">
<div id="clonedInput1" class="clonedInput">
<input type="text" id="upload_image_link_1" class="image" size="36" name="hero_options[upload_image_link_1]" value="' . $hero_options['upload_image_link_1'] . '" />
<input id="show_upload_image_link_button_1" class="button upload_images" type="button" value="Upload Image" />
<button class="remove">Remove</button>
</div>
</div>
자바 스크립트를 몇 번, 어떤 양식을 삭제하면 떨어져 형태
function updateClonedInput(index, element) {
$(element).appendTo("#upload_image_sets").attr("id", "clonedInput" + index);
$(element).find(">:first-child").attr("id", "cs_product_menu_img_src_" + index);
$(element).find(">:first-child").attr("name", "hero_options[upload_image_link_" + index + "]");
$(element).find(">:first-child").attr("value", "");
$(element).find(">:first-child").next().attr("id", "cs_product_menu_img_src_" + index + "_button");
displayRemove();
}
function displayRemove() {
if ($('.clonedInput').length === 1) {
$('.remove').hide();
} else {
$('.remove').show();
}
}
displayRemove();
$(document).on("click", ".clone", function (e) {
e.preventDefault();
var cloneIndex = $(".clonedInput").length + 1;
var new_Input = $(this).closest('.clonedInput').length ? $(this).closest('.clonedInput').clone() : $(".clonedInput:last").clone();
updateClonedInput(cloneIndex, new_Input);
});
$(document).on("click", ".remove", function (e) {
e.preventDefault();
$(this).parents(".clonedInput").remove();
$(".clonedInput").each(function (cloneIndex, clonedElement) {
updateClonedInput(cloneIndex + 1, clonedElement);
})
});
복제 형태 콘텐츠가있는 첫 번째 콘텐츠는 첫 번째 양식의 내용을 알 수 있습니다. NT 삭제, 나는 이것을 혼자두고 싶다.
에서 차용'id' 모든 복제에 속성을? 복제, 추가 및 값 지우기가 훨씬 적은 코드로 수행 될 수 있기 때문에 나는 묻습니다. – andyb