大侠们好,问题是这样的:前端商品列表显示  显示的规则就是 商品名称前面有一个单选框,选择单选的商品点击确定按钮将选择的商品名称赋值给后面的文本框,目前这个功能已经实现,现在就是希望追加显示。追加显示就是再次选择并且确认文本框中就以逗号隔开 追加显示商品名称,如:  【a商品,b商品,...】因为对jquery不是很熟,搜了半天没解决 求大侠帮忙!

解决方案 »

  1.   

    $("#qSchoolName").val($("#qSchoolName").val()+'aa');
      

  2.   


    <script src="http://www.coding123.net/js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var txt = $('#txt')[0];
            $('input:checkbox').click(function () {
                if (this.checked) txt.value += ',' + this.nextSibling.data;
                else txt.value = txt.value.replace(',' + this.nextSibling.data, '');
            });
        });
    </script>
    <div><input type="checkbox" />商品1</div>
    <div><input type="checkbox" />商品2</div>
    <div><input type="checkbox" />商品3</div>
    <div><input type="checkbox" />商品4</div>
    <div><input type="checkbox" />商品5</div>
    <input type="text" style="width:100%" id="txt">
      

  3.   


     <script src="http://www.coding123.net/js/jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $("#btnConfirm").bind("click", function () {
                    $("#txt").val("");
                    var txtValue = "";
                    $("input[type='checkbox']:checked").each(function () {
                        var text = $.trim($(this).parent("div").text());
                        if (txtValue.indexOf(text) == -1) {
                            if (txtValue == "")
                                txtValue = text;
                            else {
                                txtValue += "," + text;  
                            }
                        }
                    });
                    $("#txt").val(txtValue);
                });
            })
        </script>
        <div>
            <input type="checkbox" />商品1
        </div>
        <div>
            <input type="checkbox" />商品2
        </div>
        <div>
            <input type="checkbox" />商品3
        </div>
        <div>
            <input type="checkbox" />商品4
        </div>
        <div>
            <input type="checkbox" />商品5
        </div>    <input type="button" id="btnConfirm" value="confirm" />
        <input type="text" style="width: 100%" id="txt">