您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了如何實(shí)現(xiàn)JavaScript, select標(biāo)簽元素左右移動(dòng)功能,內(nèi)容簡(jiǎn)而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來(lái)看看吧。
通過(guò)JavaScript設(shè)計(jì)一段代碼,實(shí)現(xiàn)下面的功能.初始界面如下圖,選中左面標(biāo)簽中的幾個(gè)選項(xiàng)后再點(diǎn)-->,則將他們移動(dòng)到右側(cè)框內(nèi),同時(shí)左側(cè)選項(xiàng)消失.點(diǎn)擊====>后,左側(cè)全部選項(xiàng)移動(dòng)到右側(cè).點(diǎn)擊右側(cè)幾個(gè)選項(xiàng)后,再點(diǎn)<---,則這些選項(xiàng)移動(dòng)到左側(cè),點(diǎn)<====,則右側(cè)全部選項(xiàng)移動(dòng)到左側(cè).代碼如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> #box_L,#choice,#box_R{ display: inline-block; } </style> </head> <body> <div id="box_L"> <select id="left" multiple size="10"> <option>one</option> <option>two</option> <option>three</option> <option>four</option> <option>five</option> <option>six</option> </select> </div> <div id="choice"> <input type="button" width="5px" value="--->" onclick="add()"><br> <input type="button" width="5px" value="====>" onclick="addall()"><br> <input type="butoon" width="5px" value="<---" onclick="sub()"><br> <input type="butoon" width="5px" value="<====" onclick="suball()"><br> </div> <div id="box_R"> <select id="right" size="10" multiple> <option>seven</option> </select> </div> <script> var left=document.getElementById("left"); var right=document.getElementById("right"); function add(){ var options=left.children; for (var i=0;i<options.length;i++){ if (options[i].selected==true){ options[i].selected=false; right.appendChild(options[i]); i--; } } } function addall(){ var options=left.children; for (var i=0;i<options.length;i++){ right.appendChild(options[i]); i--; } } function sub(){ var options=right.children; for (var i=0;i<options.length;i++){ if (options[i].selected==true){ options[i].selected=false; left.appendChild(options[i]); i--; } } } function suball(){ var options=right.children; for (var i=0;i<options.length;i++){ left.appendChild(options[i]); i--; } } </script> </body> </html>
結(jié)果如下
以上就是關(guān)于如何實(shí)現(xiàn)JavaScript, select標(biāo)簽元素左右移動(dòng)功能的內(nèi)容,如果你們有學(xué)習(xí)到知識(shí)或者技能,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。