Javascript 从选中的复选框中获取所有值并放入文本区域

Javascript 从选中的复选框中获取所有值并放入文本区域,javascript,html,Javascript,Html,我想让javascript将我所有的复选框值放入一个文本区域,一旦取消选中,它将从数组中弹出。。。以下是代码: <form enctype="multipart/form-data" method="get" id="frmMain" name="frmMain"> <input type = "checkbox" id = "chk1" value = "CheckBox1" onclick ='checkTickArea(this.id)'> <

我想让javascript将我所有的复选框值放入一个文本区域,一旦取消选中,它将从数组中弹出。。。以下是代码:

<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>

此外,此功能仅适用于firefox。。。但是在Chrome和IE中,它不起作用…

这对我来说很有效,尽管我不知道为什么不使用jQuery作为文本区域:

HTML:


删除内联javascript并执行以下操作:

var elems = $('[id^="chk"]');

elems.on('change', function() {
    $('#taSignOff').val(
        elems.filter(':checked').map(function() {
            return this.value;
        }).get().join("->\n")
    );
});

…checkTickArea函数在哪里?向我们展示您尝试过的javascript抱歉,我忘了添加。。。好了,我现在编辑了这个问题@门把手现在对不起,我忘了添加。。。好了,我现在编辑了这个问题@leemoSo每次单击复选框时,是否添加另一个onchange事件处理程序?
<form enctype="multipart/form-data" method="get" id="frmMain" name="frmMain">
    <input type = "checkbox" id = "chk1" value = "CheckBox1" /> 
    <input type = "checkbox" id = "chk2" value = "CheckBox2" /> 
    <input type = "checkbox" id = "chk3" value = "CheckBox3" /> 
    <input type = "checkbox" id = "chk4" value = "CheckBox4" /> 
    <input type = "checkbox" id = "chk5" value = "CheckBox5" />
    <textarea id= "taSignOff" style="width:180px;height:90px;font-size:20px; resize: none;" rows="3" readonly> </textarea>
</form>
var selectedvalue = [];

$('input[type="checkbox"]').on('change', checkTickArea);

function checkTickArea() {

    //If checked then push the value
    if ($(this).is(":checked")) {
        selectedvalue.push($(this).val());
    } else {
        selectedvalue.splice(selectedvalue.indexOf($(this).val()), 1);
    }

    // Why not use jQuery tho?
    //$('taSignOff').val(selectedvalue.join("->\n"));
    document.getElementById('taSignOff').value = selectedvalue.join("->\n");
}
var elems = $('[id^="chk"]');

elems.on('change', function() {
    $('#taSignOff').val(
        elems.filter(':checked').map(function() {
            return this.value;
        }).get().join("->\n")
    );
});