社区
JavaScript
帖子详情
在ListBox中,如何获得选中的所有项的值?
zher
2003-12-12 04:07:28
如题?
...全文
48
1
打赏
收藏
在ListBox中,如何获得选中的所有项的值?
如题?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
slumcherry
2003-12-12
打赏
举报
回复
<FORM METHOD=POST ACTION="" name="form1">
<SELECT NAME="ss" multiple>
<option>aaa</option>
<option>bbb</option>
<option>ccc</option>
<option>ddd</option>
<option>eee</option>
<option>fff</option>
</SELECT>
</FORM>
<INPUT TYPE="button" value="click" onclick="show()" id="slum">
<SCRIPT LANGUAGE="JavaScript">
<!--
function show()
{
var str=""
var len=document.form1.ss.options.length
for(var i=0;i<len;i++)
{
if(document.form1.ss.options[i].selected==true)
{
str=str+document.form1.ss.options[i].text + ","
}
}
alert(str)
}
//-->
</SCRIPT>
当然还可以保存在数组里.
ListBox
获
值
.,测试通过。
ListBox
获
值
.,测试通过。
双击
listbox
某一行,使这行的某个内容出现在编辑框
中
。
双击
listbox
某一行,使这行的某个内容出现在编辑框
中
。
VB6.0
ListBox
应用实例
关于
ListBox
和Combo的联合应用实例,具有较好的参考价
值
!
QQ好友列表控件_C#
QQ好友例表控件 带实例和源码 //1. 属性列表: // SelectionMode 组件
中
条目的选择类型,即多选(Multiple)、单选(Single) // Rows 列表框
中
显示总共多少行 // Selected 检测条目是否被
选
中
// SelectedItem 返回的类型是ListItem,
获得
列表框
中
被选择的条目 // Count 列表框
中
条目的总数 // SelectedIndex 列表框
中
被选择
项
的索引
值
// Items 泛指列表框
中
的所有
项
,每一
项
的类型都是ListItem //2. 取列表框
中
被
选
中
的
值
//
ListBox
.SelectedValue //3. 动态的添加列表框
中
的
项
: //
ListBox
.Items.Add("所要添加的
项
"); //4. 移出指定
项
: // //首先判断列表框
中
的
项
是否大于0 // If(
ListBox
.Items.Count > 0 ) // { ////移出选择的
项
//
ListBox
.Items.Remove(
ListBox
.SelectedItem); // } //5. 清空所有
项
: // //首先判断列表框
中
的
项
是否大于0 // If(
ListBox
.Items.Count > 0 ) // { ////清空所有
项
//
ListBox
.Items.Clear(); // } //6. 列表框可以一次选择多
项
: // 只需设置列表框的属性 SelectionMode="Multiple",按Ctrl可以多选 //7. 两个列表框联动,即两级联动菜单 // //判断第一个列表框
中
被
选
中
的
值
// switch(
ListBox
1.SelectValue) // { ////如果是"A",第二个列表框
中
就添加这些: //case "A" //
ListBox
2.Items.Clear(); //
ListBox
2.Items.Add("A1"); //
ListBox
2.Items.Add("A2"); //
ListBox
2.Items.Add("A3"); ////如果是"B",第二个列表框
中
就添加这些: //case "B" //
ListBox
2.Items.Clear(); //
ListBox
2.Items.Add("B1"); //
ListBox
2.Items.Add("B2"); //
ListBox
2.Items.Add("B3"); // } //8. 实现列表框
中
项
的移位 // 即:向上移位、向下移位 // 具体的思路为:创建一个
ListBox
对象,并把要移位的
项
先暂放在这个对象
中
。 // 如果是向上移位,就是把当前选定
项
的的上一
项
的
值
赋给当前选定的
项
,然后 // 把刚才新加入的对象的
值
,再附给当前选定
项
的前一
项
。 // 具体代码为: // //定义一个变量,作移位用 // index = -1; // //将当前条目的文本以及
值
都保存到一个临时变量里面 // ListItem lt=new ListItem (
ListBox
.SelectedItem.Text,
ListBox
.SelectedValue); // //被
选
中
的
项
的
值
等于上一条或下一条的
值
//
ListBox
.Items[
ListBox
.SelectedIndex].Text=
ListBox
.Items[
ListBox
.SelectedIndex + index].Text; // //被
选
中
的
项
的
值
等于上一条或下一条的
值
//
ListBox
.Items[
ListBox
.SelectedIndex].Value=
ListBox
.Items[
ListBox
.SelectedIndex + index].Value; // //把被
选
中
项
的前一条或下一条的
值
用临时变量
中
的取代 //
ListBox
.Items[
ListBox
.SelectedIndex].Test=lt.Test; // //把被
选
中
项
的前一条或下一条的
值
用临时变量
中
的取代 //
ListBox
.Items[
ListBox
.SelectedIndex].Value=lt.Value; // //把鼠标指针放到移动后的那
项
上 //
ListBox
.Items[
ListBox
.SelectedIndex].Value=lt.Value; //9. 移动指针到指定位置: // (1).移至首条 // //将被
选
中
项
的索引设置为0就OK了 //
ListBox
.SelectIndex=0; // (2).移至尾条 // //将被
选
中
项
的索引设置为
ListBox
.Items.Count-1就OK了 //
ListBox
.SelectIndex=
ListBox
.Items.Count-1; // (3).上一条 // //用当前被
选
中
的索引去减 1 //
ListBox
.SelectIndex=
ListBox
.SelectIndex - 1; // (4).下一条 // //用当前被
选
中
的索引去加 1 //
ListBox
.SelectIndex=
ListBox
.SelectIndex + 1; //this.
ListBox
1.Items.Insertat(3,new ListItem("插入在第3行之后
项
","")); //this.
ListBox
1.Items.Insertat(index,ListItem) //
ListBox
1.Items.Insert(0,new ListItem("text","value"));
C#语言知识点要点总结
C#知识总结,点一个按钮弹出打开对话框、向
listbox
控件
中
初始化
值
、从左侧
listbox
向右侧lisbox
中
添加单条
项
JavaScript
87,996
社区成员
224,708
社区内容
发帖
与我相关
我的任务
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
分享
社区描述
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章