色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

JavaScript關于select的相關操作說明

一、 插入option
1、DOM方法
var oSelectYear = document.getElementById("SelectYear");
var op = document.createElement("option");
op.innerHTML = "2010";
op.value = "2010";
oSelectYear.appendChild(op);

2、new Option方法
var oSelectMonth = document.getElementById("SelectMonth");
oSelectMonth.options.add(new Option(1, 1));
oSelectMonth.options.add(new Option(2, 2));

二、 清空option
var oSelectMonth = document.getElementById("SelectMonth");
oSelectMonth.options.length = 0; //清空Select里面的options

三、 設置默認選中option
var oSelectMonth = document.getElementById("SelectMonth");
//oSelectMonth.selectedIndex = 1; //方法一:默認選中第二項
//setTimeout(function() { oSelectMonth.selectedIndex = 1; }, 0); //用setTimeout延遲是為了防止dom渲染問題
// oSelectMonth.options[1].selected = true; //方法二
oSelectMonth.options[1].setAttribute("selected", "true"); //方法三:比較推薦的用setAttribute來設置

JavaScript技術JavaScript關于select的相關操作說明,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 密山市| 金山区| 丰城市| 玛沁县| 黄龙县| 江源县| 尼玛县| 东方市| 太保市| 昌都县| 英德市| 防城港市| 武鸣县| 仁化县| 蒙阴县| 承德市| 江陵县| 博爱县| 工布江达县| 威宁| 通榆县| 泾川县| 彰化市| 休宁县| 修水县| 岳阳市| 德保县| 怀化市| 江川县| 永福县| 新兴县| 都昌县| 井冈山市| 庐江县| 乐平市| 碌曲县| 重庆市| 四子王旗| 大丰市| 宣汉县| 聂拉木县|