select_form エフェクトの JavaScript 関連の操作手順

WBOY
リリース: 2016-05-16 18:36:31
オリジナル
1032 人が閲覧しました
1. オプションを挿入します
1. DOM メソッド
var oSelectyear = document.getElementById("Select Year");
var op = document.createElement("option"); op.innerHTML = "2010";
op.value = "2010";

2. 新しいオプション メソッド
var oSelectMonth = document.getElementById( "SelectMonth");
oSelectMonth.options.add(新しいオプション(1, 1));


2. オプションをクリアします

var oSelectMonth = document.getElementById("SelectMonth"); oSelectMonth.options.length = 0; //Select のオプションをクリアします

3 ,デフォルトの選択されたオプションを設定します

var oSelectMonth = document.getElementById("SelectMonth"); //oSelectMonth.selectedIndex = 1; //方法 1: 2 番目の項目がデフォルトで選択されます/ /setTimeout (function() { oSelectMonth.selectedIndex = 1; }, 0); //DOM レンダリングの問題を防ぐために setTimeout 遅延を使用します
// oSelectMonth.options[1].selected = true; > oSelectMonth.options[1].setAttribute("selected", "true"); //方法 3: setAttribute を使用して設定することをお勧めします
関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!