양식 외부의 테이블에서 양식에 동적으로 추가하려고합니다.> 기본 양식이 있고 요약 테이블에서 원하는 양식을 선택합니다. 양식에 요소를 추가하는 편집 버튼을 클릭하십시오. 아래는 숨겨진 필드를 추가하는 첫 번째 시도입니다. 숨겨진 필드가있는 div가 있습니다.jquery 양식 외부 버튼에서 숨겨진 div에 숨겨진 필드를 추가하려고합니다.
다음 코드는 다음과 같습니다. 내가 보여주는 테이블은 실제로 스크롤 테이블과 div 디자인에 있습니다. 나는이 함수에 대한 기본 요소를 제거했다.
<form id="incidentform" action="" method="get">
<div id="hidfielddiv">
<input type="hidden" name="mchnum" value="346"/>
<input type = "hidden" name="mchemploy" value="1"/>
<input type = "hidden" name="persontypeid" id="persontypeid" value="2"/>
</div>
<label class="main">Employee Information</label>
<label class="empname">Name</label>
<label class="empname">Nursing Assistant - 80</label>
<input type="submit" class="button" id="addincidentButton" name="addincidentButton" value="Add Incident"/>
</form>
<table>
<tr>
<td style="display: none;">0</td>
<td style="display: none;">2</td>
<td>11/12/2014</td>
<td>4:04 PM</td>
<td>
<input type="button" class="button" class="editincidentbutton" value="Edit incident" />
</td>
</tr>
</table>
표에서 볼 수 있듯이이 표는 양식 외부에 있으며 스크립트는 다음과 같습니다.
$(function(){
$(".editincidentbutton").click(function(){
$('<input>').attr({
type: 'hidden',
id: 'superwitness',
name: 'superwitness',
value: '0'
}).appendto("#hidfielddiv");
}
)
})
버튼에 두 개의 클래스 속성이 있습니다. click 이벤트는 그 때문에 트리거되지 않습니다. 이'class = "button ="editincidentbutton "class에 대한 editincidentbutton 클래스를 수정하십시오 editacidentbutton" – balzafin