javascript擷取表單中多個input控制項checkbox類型(用戶端控制項)的值

來源:互聯網
上載者:User

1,前台代碼:

//<input id="zonestr" runat="server" type="text" style="display:none" />

//該控制項的作用是存放擷取到的多項input的值,用於與後台代碼的互動

 

 

<div class="multisele_content" id="div1" onclick="javascript:GetZone()">
                    <input id="zonestr" runat="server" type="text" style="display:none" />
                    <div class="multisele_content_box">
                 <div class="se_box">
                     <input id="zonexiyao" runat="server" type="checkbox" class="se_chk" checked="true" name="zone" value="西藥"/>
                        <p>西藥</p>
                    </div>
                    <div class="se_box">
                     <input  id="zonezhongyao" runat="server" type="checkbox" class="se_chk" name="zone" value="中藥"/>
                        <p> 中藥</p>
                    </div>
                    <div class="se_box">
                     <input  id="zoneshengwu" runat="server" type="checkbox" class="se_chk" name="zone" value="生物藥"/>
                        <p>生物藥</p>
                    </div>
                    <div class="se_box">
                     <input  id="zonehuaxueyuanliao" runat="server" type="checkbox" class="se_chk" name="zone" value="化學原料藥"/>
                        <p>化學原料藥</p>
                    </div>
                    <div class="se_box">
                     <input  id="zoneyaobao_fuliao" runat="server" type="checkbox" class="se_chk" name="zone" value="藥包材,輔料"/>
                        <p>藥包材,輔料</p>
                    </div>
                    <div class="se_box" style="width:200px;">
                     <input  id="zonehuagong_zhongjian" runat="server" type="checkbox" class="se_chk" name="zone" value="化工產品及中間體"/>
                        <p>化工產品及中間體</p>
                    </div>
                </div>
                <div class="multisele_content_box">
                 <div class="se_box">
                     <input  id="zonezhongyao_yinping" runat="server" type="checkbox" class="se_chk"  name="zone" value="中藥材及飲片"/>
                        <p>中藥材及飲片</p>
                    </div>
                    <div class="se_box">
                     <input  id="zonezhiwutiqu" runat="server" type="checkbox" class="se_chk" name="zone" value="植物提取物"/>
                        <p>植物提取物</p>
                    </div>
                    <div class="se_box" style="width:140px;">
                     <input  id="zonebiaozhun_zhenduan" runat="server" type="checkbox" class="se_chk" name="zone" value="標準品,診斷試劑"/>
                        <p>標準品,診斷試劑</p>
                    </div>
                    <div class="se_box">
                     <input  id="zoneyiliaoqixie" runat="server" type="checkbox" class="se_chk" name="zone" value="醫學器械"/>
                        <p>醫學器械</p>
                    </div>
                    <div class="se_box">
                     <input  id="zoneyiqishebei" runat="server" type="checkbox" class="se_chk" name="zone" value="儀器裝置"/>
                        <p>儀器裝置</p>
                    </div>
                    <div class="se_box">
                     <input  id="zonebaojianshipin" runat="server" type="checkbox" class="se_chk" name="zone" value="保健食品"/>
                        <p>保健食品</p>
                    </div>
                    <div class="se_box" style="width:60px;">
                     <input  id="zoneother" runat="server" type="checkbox" class="se_chk" name="zone" value="其他"/>
                        <p>其他</p>
                    </div>
                </div>
                    </div> 

 

2,js代碼:

//擷取經營範圍
function GetZone()
{

//擷取input所在div的對象
    var ob = document.getElementById("div1");

//擷取div中所用的IUPUT控制項集合
    var col = div1.getElementsByTagName("INPUT");
    var str="";
    var count=0;

//迴圈遍曆,判斷INPUT是否選中
    for(var i=0 ;i<col.length;i++)
    {
        if(col[i].checked==true)
        {
            count++;
            if(count==1)
            {
                str+=col[i].value;
            }
            else
            {
                str+="/"+col[i].value;
            }
            //str+=col[i].value+"/";
        }
    }
    document.getElementById("zonestr").value=str;
    //alert(document.getElementById("zonestr").value);
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.