자바 스크립트로 모든 체크 박스 값을 텍스트 영역에 넣고 한 번 선택 해제하면 배열에서 팝업됩니다. 여기 코드는체크 된 체크 박스에서 모든 값 가져 오기 및 텍스트 영역에 넣기
입니다.<form enctype="multipart/form-data" method="get" id="frmMain" name="frmMain">
<input type = "checkbox" id = "chk1" value = "CheckBox1" onclick ='checkTickArea(this.id)'>
<input type = "checkbox" id = "chk2" value = "CheckBox2" onclick = 'checkTickArea(this.id)'>
<input type = "checkbox" id = "chk3" value = "CheckBox3" onclick = 'checkTickArea(this.id)'>
<input type = "checkbox" id = "chk4" value = "CheckBox4" onclick = 'checkTickArea(this.id)'>
<input type = "checkbox" id = "chk5" value = "CheckBox5" onclick = 'checkTickArea(this.id)'>
<textarea id= "taSignOff" style="width:180px;height:90px;font-size:20px; resize: none;" rows="3" readonly> </textarea>
</form>
자바 스크립트 : 또한이 기능은 파이어 폭스에서 작동 ...하지만 크롬과 IE에서 작동하지 않습니다
var selectedvalue=[];
function checkTickArea(id)
{
$('#'+id).change(function() {
//If checked then push the value
if($('#'+id).is(":checked"))
{
selectedvalue.push($('#'+id).attr("value"));
}else
{
//This is what pops the value from the array when the checkbox is unchecked.
/* var index = selectedvalue.indexOf($('#'+id).attr("value"));
if (index > -1) {
selectedvalue.splice(index, 1);
}*/
selectedvalue.splice(selectedvalue.indexOf($(this).attr("value")),1);
}
document.getElementById('taSignOff').value = selectedvalue.join("->\n");
});
}
... 이것은 나를 위해 작동
... 'checkTickArea' 함수는 어디에 있습니까? – Doorknob
당신이 시도한 자바 스크립트를 보여주세요 – hammus
죄송합니다. 추가하는 것을 잊어 버렸습니다 ... 거기에 가서 질문을 편집했습니다 ... @DoorknobofSnow – k3vin023