---
title: "js操作select"
author: "xchyou"
date: "2012-09-13T10:05:13Z"
tags: ["js select option"]
categories: ["Web前端"]
slug: "js-select"
draft: false
lastmod: "2012-09-13T10:08:41Z"
id: 1677527
url: "https://xchyou.iteye.com/blog/1677527"
---

//已经选中的(accList是select的id)

var id = document.all.accList.selectedIndex;

var values = document.all.accList.options\[id].value;

var accid = document.all.accList.options\[id].text;

 

//动态新增(删除)option

var selects = document.getElementsByTagName('select');

 

var optionNode = new Option(eo.packageid,eo.packageid);

selects\[0].add(optionNode);

 

var options = selects\[0].options.length;

 

for(var i = options-1;i &gt;= 1;i--)

{  

selects\[0].options.remove(i);

}