zoukankan
html css js c++ java
javscript操作Select标签[动态添加,清空]
<!
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=gb2312"
/>
<
title
>
无标题文档
</
title
>
<
script
type
="text/javascript"
>
function
addList()
{
var
list
=
document.getElementById(
"
list
"
);
for
(
var
i
=
1
; i
<=
5
; i
++
)
{
var
newOption
=
document.createElement(
"
option
"
);
newOption.setAttribute(
"
value
"
, i);
newOption.appendChild(document.createTextNode(
"
测试数据
"
+
i));
list.appendChild(newOption);
}
}
function
clearList()
{
var
list
=
document.getElementById(
"
list
"
);
for
(
var
i
=
list.options.length; i
>=
0
; i
--
)
{
list.remove(i);
}
//
注意:每删除一个option其它option的index特性会自动重置,因此,按以下方法(即从上往下删是清除不了的)
//
for(var i = 0; i< list.options.length; i++){
//
list.remove(i);
//
}
}
</
script
>
</
head
>
<
body
>
<
select
name
="list"
id
="list"
>
</
select
>
<
input
type
="button"
onclick
="addList()"
value
="生成"
/>
<
input
type
="button"
onblur
="clearList()"
value
="清空"
/>
</
body
>
</
html
>
查看全文
相关阅读:
Selenium笔记(三)--WebDriver 等待、支持的类、javaScript警告框、提示框、确认框、Http代理、页面加载策略、网络元素、Keyboard;远程WebDriver
Selenium3+python3自动化(四十八)--阿里云centos7上搭建selenium启动chrome浏览器headless无界面模式
Selenium3+python3自动化(四十七)--定位的坑:class属性有空格
Selenium3+python3自动化(四十六)--弹窗处理(PyKeyboard) tab切换,enter回车,输入
Selenium3+python3自动化(四十五)--弹出框死活定位不到
Selenium3+python3自动化(四十四)--行为事件(ActionChains)源码详解
Selenium3+python3自动化(四十三)--爬取我的博客园粉丝的名称,并写入.text文件
Selenium3+python3自动化(四十二)--批量操作循环点击报错
Selenium3+python3自动化(四十一)--Chrome浏览器静默模式启动(headless)
Selenium3+python3自动化(四十)--Chrome正在受到自动软件的控制
原文地址:https://www.cnblogs.com/ywkpl/p/1123655.html
最新文章
实验十
实验九
HackGame
实验七
实验六
背包加数论 SCOI2009
01背包(阴阳师)
简单的钱币兑换
快速幂加逆元!
星球大战 并查集!!!
热门文章
POJ--1990(排序+树状数组)
牛客算法周周练10 E-跳石头(二分)
POJ--3321(dfs序树状转线性+树状数组+vector防超时写法)
Codeforces Round #648 (Div. 2)A-E(伪博弈+思维+暴力+BFS+思维/暴力/位运算)
Codeforces Round #647 (Div. 2) C题(结论)两种方法
Codeforces Round #647 (Div. 2)B题(暴力模拟)
Codeforces Round #647 (Div. 2) A题(贪心)
POJ--2182剩余第K大(暴力/树状数组+二分)
UVA133(约瑟夫环变种)
牛客算法周周练9 D-石子游戏(简单博弈)
Copyright © 2011-2022 走看看