点击复选框添加或删除value值到input输入框中

点击复选框添加或删除value值到input输入框中jsp


使用js实现勾选复选框,添加复选框的内容到文本框,去掉勾选,删除文本框中相应的内容。this

jsp:spa

<input type="text" id="jsrtxt" class="tip" />ip

<label><input type="checkbox" name="aaa" value="1"/>复选1</label>
<label><input type="checkbox" name="aaa" value="1"/>复选2</label>
<label><input type="checkbox" name="aaa" value="1"/>复选3</label>
input



js:io

$("input[type=checkbox]").click(function () {
            if ($(this).attr("checked")) {
                     $("#jsrtxt").val($("#jsrtxt").val() + $(this).parent().text() + ";");
             } else {
                     $("#jsrtxt").val($("#jsrtxt").val().replace($(this).parent().text() + ';', ""));
             }
 });
function

相关文章
相关标签/搜索