js實現擷取值傳到input裡邊

來源:互聯網
上載者:User

標籤:

代碼<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">    <head>        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">        <title>Document</title>        <style>                </style>        <script>        function checkAll(e, itemName, thisValue){            var target = document.getElementById(‘arrayid‘);            var targetValue = target.value;            var inputs = document.getElementsByName(itemName);            if (e.checked == true) {                targetValue += thisValue + ‘,‘;            } else {                targetValue = targetValue.replace(thisValue + ‘,‘, ‘‘);            }            target.value = targetValue;            for(var i=0; i<inputs.length; i++){                inputs[i].checked = e.checked;            }        }        </script>    </head>    <body>        <form>            <p>                <input type="checkbox" value="1001" name="1001" id="1001" onclick="checkAll(this, ‘mk1001‘, ‘1001‘)">                <label for="1001">複選1</label>                <input name="mk1001" type="checkbox" id="mk1001" value="1" />                <input name="mk1001" type="checkbox" id="mk1002" value="2" />                <input name="mk1001" type="checkbox" id="mk1003" value="3" />                <input name="mk1001" type="checkbox" id="mk1004" value="4" />                <input name="mk1001" type="checkbox" id="mk1005" value="5" />            </p>            <p>                <input type="checkbox" value="1002" name="1002" id="1002" onclick="checkAll(this, ‘mk1002‘, ‘1002‘)">                <label for="1002">複選2</label>                <input name="mk1002" type="checkbox" id="mk1001" value="6" />                <input name="mk1002" type="checkbox" id="mk1002" value="7" />                <input name="mk1002" type="checkbox" id="mk1003" value="8" />                <input name="mk1002" type="checkbox" id="mk1004" value="9" />                <input name="mk1002" type="checkbox" id="mk1005" value="10" />            </p>            <p>                <input type="checkbox" value="1003" name="1003" id="1003" onclick="checkAll(this, ‘mk1003‘, ‘1003‘)">                <label for="1003">複選3</label>                <input name="mk1003" type="checkbox" id="mk1001" value="11" />                <input name="mk1003" type="checkbox" id="mk1002" value="12" />                <input name="mk1003" type="checkbox" id="mk1003" value="13" />                <input name="mk1003" type="checkbox" id="mk1004" value="14" />                <input name="mk1003" type="checkbox" id="mk1005" value="15" />            </p>            <p>                <input type="checkbox" value="1004" name="1004" id="1004" onclick="checkAll(this, ‘mk1004‘, ‘1004‘)">                <label for="1004">複選4</label>                <input name="mk1004" type="checkbox" id="mk1001" value="11" />                <input name="mk1004" type="checkbox" id="mk1002" value="12" />                <input name="mk1004" type="checkbox" id="mk1003" value="13" />                <input name="mk1004" type="checkbox" id="mk1004" value="14" />                <input name="mk1004" type="checkbox" id="mk1005" value="15" />            </p>            <p>                請把複選1,2,3的值傳到以下的框中,中間以,號分隔            </p>            <p>                <input type="text" id="arrayid" />            </p>        </form>    </body></html>

 

js實現擷取值傳到input裡邊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.