點擊checkbox 向input 里面傳值顯示


文本框顯示
<input type="text" id="textareashow" name="" class="margin-bottom-10 newbz floatleft"/>

check1:
<input type="checkbox" data-type="checkbox" data-value="等通知放貨(送貨)" value="等通知放貨(送貨)">等通知放貨(送貨)

check2:
<input type="checkbox" data-type="checkbox" data-value="等通知放貨(自提)" value="等通知放貨(自提)">等通知放貨(自提)
<script type="text/javascript">
            $(function() {
                $('[data-type="checkbox"]').click(function() {
                    var data_value = $(this).attr('data-value'),
                        txtalso = $.trim($("#textareashow").val());
                    if ($(this).prop("checked")) {
                        if (txtalso.length > 0) {
                            if (txtalso.indexOf(data_value + ',') != -1) {
                                return;
                            } else {
                                txtalso += data_value + ',';
                            }
                        } else {
                            txtalso = data_value + ',';
                        }
                    } else {
                        if (txtalso.indexOf(data_value + ',') != -1) {
                            txtalso = txtalso.replace(data_value + ',', '');
                        }
                    }
                    $("#textareashow").val(txtalso);
                });
            });
        </script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM