日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

js实际运用

發布時間:2025/4/16 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 js实际运用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實現效果:點擊添加,左邊框中的選中項消失,添加到右邊的框中;點擊移除,右邊的不消失,但會增加到左邊的框中。

代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><style>#ListBox1, #ListBox2 {width: 200px;height: 200px;float: left;}</style></head> <body><form id="form1" runat="server"><div><asp:ListBox ID="ListBox1" SelectionMode="Multiple" runat="server"><asp:ListItem Value="1111">蘋果</asp:ListItem><asp:ListItem Value="222">橘子</asp:ListItem><asp:ListItem Value="333">香蕉</asp:ListItem><asp:ListItem Value="444">葡萄</asp:ListItem><asp:ListItem Value="55">張柯</asp:ListItem></asp:ListBox><div style="float: left;"><input type="button" id="btn1" value="添加>>>" /><br /><input type="button" id="btn2" value="<<<移除" /><input type="button" id="btn_ok" value="確定" /></div><asp:ListBox ID="ListBox2" runat="server"></asp:ListBox></div></form> </body> </html><script src="JavaScript.js"></script> <script src="JavaScript2.js"></script>

兩段js碼,第一個為添加,第二個為移除;移除中,創建一個新對象,將原對象的值賦給新對象,添加新對象,則原對象不會消失

var oBtn1 = document.getElementById("btn1");oBtn1.onclick = function () {//取出ListBox1中的選中項var lb1 = document.getElementById("ListBox1");for (var i = 0; i < lb1.options.length; i++) {if (lb1.options[i].selected == true) {document.getElementById("ListBox2").appendChild(lb1.options[i]);}} }; var oBtn2 = document.getElementById("btn2");oBtn2.onclick = function () {var olb2 = document.getElementById("ListBox2");for (var i = 0; i < olb2.options.length; i++) {if (olb2.options[i].selected == true) {var op = document.createElement("option");op.value = olb2.options[i].value;op.innerHTML = olb2.options[i].innerHTML;document.getElementById("ListBox1").appendChild(op);}} };

?

轉載于:https://www.cnblogs.com/wy1992/p/6278639.html

總結

以上是生活随笔為你收集整理的js实际运用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。