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
>
查看全文
相关阅读:
mybatis-plus代码生成模板
Flask_APScheduler的简单使用
Linux 配置mysql 远程连接
ubuntu19.04 安装mysql,没有初始密码,重设初始密码
ubuntu19.04 配置远程连接ssh
python3 win 建立虚拟环境(virtualenv)
python property(不动产)方法
python,装饰器带参数,原理
利用python装饰器为字符串添加,HTML标签
python pymysql 基本使用
原文地址:https://www.cnblogs.com/ywkpl/p/1123655.html
最新文章
树上差分
Mountaineers
Pizza Delivery
Explosion at Cafebazaar
缩点
Spell Boost
Modulo Pairing
动物园
故障处理
复制repliction
热门文章
事务
CAS
vue动态绑定class和style
vue组件间的通信之pubsub-js
函数在vue组件间的交互
vue组件模板及组件间的引用
使用vue-cli创建工程
word从任意页开始生成页码
vim编辑器常用操作
微信授权登录开发套路
Copyright © 2011-2022 走看看