사용자가 입력란을 양식에 추가 할 수있는 동적 양식을 만들고 있습니다.jQuery : 양식 필드의 ID 찾기
사용자가 호출 "addCredit"다음 jQuery를 스크립트의 ID로 링크를 클릭<form>
<input id="title1" class="title" name="title1" type="text" value="">
<input id="productionCompany1" name="productionCompany1" type="text" value="">
<input id="year1" name="year1" type="text" value="">
<input id="role1" name="role1" type="text" value="">
<div id="newCredit"> </div>
<a href="#" id="addCredit">add another credit</a>
</form>
:
$(document).ready(function() {
var $ac = $('#addCredit');
$ac.click(function() {
/* the following two lines are where the problem lies? */
var $credInt = $(this).prev(".title");
$.get("addCredit.php", {num: $credInt},
function(data){
$('#newCredit').append(data);});
return false;
});
});
JQuery와 함수가 호출 PHP 파일을 조회 "addCredit html로는 다음과 같습니다
<?php
$int = $_GET["num"];
$int = substr($int, -1);
$int++;
?>
<input id="title<?php echo $int;?>" class="title" name="title<?php echo $int;?>" type="text" value="">
<input id="productionCompany<?php echo $int;?>" name="productionCompany<?php echo $int;?>" type="text" value="">
<input id="year<?php echo $int;?>" name="year<?php echo $int;?>" type="text" value="">
<input id="role<?php echo $int;?>" name="role<?php echo $int;?>" type="text" value="">
내 문제는 그것이 addCredit.php 페이지로 전송하고 그에 따라 양식 필드를 업데이트 할 수 있도록 적절하게 설정 자바 스크립트 변수 $ credInt을 받고있다 : 다음과 같습니다 .PHP ". 나는 또한 폼이 추가 될 때마다, 다음에 보내지는 값이 증가 된 값이라는 것을 확신 할 필요가있다.
이 작업을 수행하는 방법에 대한 의견이 있으십니까? 도와 줘서 고마워.
복제 기능이 좋기 때문에 추가 파일이 필요 없습니다. 아름다운 코드! 고맙습니다! – superUntitled