惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
C
Check Point Blog
B
Blog RSS Feed
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
小众软件
小众软件
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
GbyAI
GbyAI
The Cloudflare Blog
博客园 - 叶小钗
S
SegmentFault 最新的问题
博客园 - Franky
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
B
Blog
Jina AI
Jina AI

博客园 - 失落

第三方支付接口搜集(附下载) SelectNodes 与 XPath 配置BizTalk时提示无法连接到SQLServer上的SSODB数据库 - 失落 - 博客园 ADO Connection Strings 两台笔记本无线共享上网图解 [转]DB2 修改模式 [转]学会使用DB2指令 [转]学会使用DB2指令及故障诊断 BizTalk 宏 js JavaScript的replace方法与正则表达式结合应用讲解 - 失落 - 博客园 HTML控件事件一览表 收集一些常用的正则表达式 解javascript的caller,callee,call,apply概念 JavaScript事件的理解 javascript 事件 SQL Server 2005 如何在没有日志文件的情况下如何恢复MDF数据库文件(测试通过) 检测远程URL是否存在的三种方法 订票地址
javascript 详解各控件的操作 - 失落 - 博客园
失落 · 2008-01-30 · via 博客园 - 失落

1 检测是否有选中
if(objSelect.selectedIndex > -1) {
//说明选中
} else {
//说明没有选中
}

2.动态创建 select

function createSelect(){

var mySelect = document.createElement("select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
}

3.添加选项 option

function addOption(){

//根据id查找对象,
var obj=document.getElementById('mySelect');

//添加一个选项
obj.add(new Option("文本","值"));
}

4.删除所有选项 option

function removeAll(){
var obj=document.getElementById('mySelect');

obj.options.length=0;

}

5.删除一个选项 option

function removeOne(){
var obj=document.getElementById('mySelect');

//index,要删除选项的序号,这里取当前选中选项的序号

var index=obj.selectedIndex;
obj.options.remove(index);
}

6.获得选项 option 的值

var obj=document.getElementById('mySelect');

var index=obj.selectedIndex; //序号,取当前选中选项的序号

var val = obj.options[index].value;

7.获得选项 option 的文本

var obj=document.getElementById('mySelect');

var index=obj.selectedIndex; //序号,取当前选中选项的序号

var val = obj.options[index].text;

8.修改选项 option

var obj=document.getElementById('mySelect');

var index=obj.selectedIndex; //序号,取当前选中选项的序号

var val = obj.options[index]=new Option("新文本","新值");

9.删除 select

function removeSelect(){
var mySelect = document.getElementById("mySelect");
mySelect.parentNode.removeChild(mySelect);
}