-2
我想要放入文本區域由JavaScript,一旦選中,它將從陣列中彈出...這裏我所有的複選框值的代碼:獲取從選中的複選框全部價值,並投入一個textarea
<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>
的javascript:
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");
});
}
此外,該功能只適用於Firefox ...但在Chrome和IE瀏覽器,它不工作...
...好哪來的'checkTickArea'功能? – Doorknob
告訴我們您嘗試過的JavaScript – hammus
對不起,我忘了加...你去那裏,我編輯的問題,現在... @DoorknobofSnow – k3vin023