この記事では、HTML select オプションの詳細な説明を紹介します
javascriptHTML (select オプション) の詳細な説明
1. 基本的な理解:
var e = document.getElementById("selectId");
e。 options = new Option("text","value") ;
//option オブジェクト を作成します。つまり、
onclick
="number();">
1. select
を動的に作成します select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
}
var obj=document.getElementById ('mySelect'); add(new Option("text","value")); IE と Firefox と互換性があります
}
3. すべてのオプションを削除します
function RemoveAll(){
var obj=document.getElementById('mySelect');
obj.options.length=0;
}
4. オプションを削除します。 =document.getElementById ('mySelect');
5. オプションの値を取得します。option
var val = obj.options [index].value;
var myselet.GetelementByid ( " mySelect");
mySelect.parentNode.removeChild(mySelect);}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html"> <head> <script language=JavaScript> function $(id) { return document.getElementById(id) } function show() { var selectObj=$("area") var myOption=document.createElement("option") myOption.setAttribute("value","10") myOption.appendChild(document.createTextNode("上海")) var myOption1=document.createElement("option") myOption1.setAttribute("value","100") myOption1.appendChild(document.createTextNode("南京")) selectObj.appendChild(myOption) selectObj.appendChild(myOption1) } function choice() { var index=$("area").selectedIndex; var val=$("area").options[index].getAttribute("value") if(val==10) { var i=$("context").childNodes.length-1; var remobj=$("context").childNodes[i]; remobj.removeNode(true) var sh=document.createElement("select") sh.add(new Option("浦东新区","101")) sh.add(new Option("黄浦区","102")) sh.add(new Option("徐汇区","103")) sh.add(new Option("普陀区","104")) $("context").appendChild(sh) } if(val==100) { var i=$("context").childNodes.length-1; var remobj=$("context").childNodes[i]; remobj.removeNode(true) var nj=document.createElement("select") nj.add(new Option("玄武区","201")) nj.add(new Option("白下区","202")) nj.add(new Option("下关区","203")) nj.add(new Option("栖霞区","204")) $("context").appendChild(nj) } } function calc() { var x=$("context").childNodes.length-1; alert(x) } function remove() { var i=$("context").childNodes.length-1; var remobj=$("context").childNodes[i]; remobj.removeNode(true) } </script> <body> <p id="context"> <select id="area" on change="choice()"> </select> </p> <input type=button value="显示" onclick="show()"> <input type=button value="计算结点" onclick="calc()"> <input type=button value="删除" onclick="remove()"> </body> </html>これらのことを踏まえて、JQEURY AJAX+ を使用しました。
JSON
を使用して次のような小さな関数を実装します。
JS コード: (SELECT コードに関連するもののみ取得)
/** * @description 构件联动下拉列表 (用JQUERY 的AJAX配合JSON实现) * @prarm selectId 下拉列表的ID * @prarm method 要调用的方法名称 * @prarm temp 此处存放软件ID * @prarm url 要跳转的地址 */ function linkAgeJson(selectId,method,temp,url){ $j.ajax({ type: "get",//使用get方法访问后台 dataType: "json",//返回json格式的数据 url: url,//要访问的后台地址 data: "method=" + method+"&temp="+temp,//要发送的数据 success: function(msg){//msg为返回的数据,在这里做数据绑定 var data = msg.lists; coverJsonToHtml(selectId,data); } }); } /** * @description 将JSON数据转换成HTML数据格式 * @prarm selectId 下拉列表的ID * @prarm nodeArray 返回的JSON数组 * */ function coverJsonToHtml(selectId,nodeArray){ //get select var tempSelect=$j("#"+selectId); //clear select value isClearSelect(selectId,'0'); var tempOption=null; for(var i=0;i<nodeArray.length;i++){ //create select Option tempOption= $j('<option value="'+nodeArray[i].dm+'">'+nodeArray[i].mc+'</option> '); //put Option to select tempSelect.append(tempOption); } // 获取退化构件列表 getCpgjThgl(selectId,'thgjDm'); } /** * @description 清空下拉列表的值 * @prarm selectId 下拉列表的ID * @prarm index 开始清空的下标位置 */ function isClearSelect(selectId,index){ var length=document.getElementById(selectId).options.length; while(length!=index){ //长度是在变化的,因为必须重新获取 length=document.getElementById(selectId).options.length; for(var i=index;i<length;i++) document.getElementById(selectId).options.remove(i); length=length/2; } } /** * @description 获取退化构件列表 * @prarm selectId1 引用软件下拉列表的ID * @prarm selectId2 退化构件下拉列表的ID */ function getCpgjThgl(selectId1,selectId2){ var obj1=document.getElementById(selectId1);//引用软件下拉列表 var obj2=document.getElementById(selectId2);//退化构件下拉列表 var len=obj1.options.length; //当引用软件列表长度等于1时返回,不做操作 if(len==1){ return false; } //清空下拉列表的值,两种方式都可以 // isClearSelect(selectId2,'1'); document.getElementById(selectId2).length=1; for(var i=0;i<len; i++){ var option= obj1.options[i]; //引用软件被选中项不加入 if(i!=obj1.selectedIndex){ //克隆OPTION并添加到SELECT中 obj2.appendChild(option.cloneNode(true)); } } }
<TABLE width="100%" border=0 align="left" cellPadding=0 cellSpacing=1> <tr> <td class="Search_item_18"> <span class="Edit_mustinput">*</span>引用软件:</td> <td class="Search_content_82"> <input name="yyrjMc" id="yyrjMc" type="text" class="Search_input" tabindex="3" size="30" > <input name="yyrjDm" id="yyrjDm" type="hidden" > <input type="button" class="Search_button_select" onClick="linkAgeTree('linkage','yyrjtree','yyrjMc','yyrjDm','linkageTree','1');" value="选择..."> </td> </tr> <tr> <td class="Search_item"> <span class="Edit_mustinput">*</span>引用分版:</td> <td class="Search_content" id="yyfb"> <select name="yyfbDm" style="width:160" id="yyfbDm" onChange="getCpgjThgl('yyfbDm','thgjDm')"> </select> </td> </tr> <tr> <td class="Search_item">退化构件:</td> <td class="Search_content" id="thgj"> <select name="thgjDm" style="width:160" id="thgjDm"> <option value="-1" selected>无</option> </select> </td> </tr> </TABLE>
以上がHTML 選択オプションの詳細な説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

webdevelopmentReliesOnhtml、css、andjavascript:1)htmlStructuresContent、2)cssStylesit、および3)Javascriptaddsinteractivity、形成、

HTMLの役割は、タグと属性を使用してWebページの構造とコンテンツを定義することです。 1。HTMLは、読みやすく理解しやすいようなタグを介してコンテンツを整理します。 2。アクセシビリティとSEOを強化するには、セマンティックタグなどを使用します。 3. HTMLコードの最適化により、Webページの読み込み速度とユーザーエクスペリエンスが向上する可能性があります。

HTML、CSS、およびJavaScriptは、Web開発の3つの柱です。 1。HTMLは、Webページ構造を定義し、などなどのタグを使用します。2。CSSは、色、フォントサイズなどのセレクターと属性を使用してWebページスタイルを制御します。

HTMLはWeb構造を定義し、CSSはスタイルとレイアウトを担当し、JavaScriptは動的な相互作用を提供します。 3人はWeb開発で職務を遂行し、共同でカラフルなWebサイトを構築します。

HTMLは、簡単に学習しやすく、結果をすばやく見ることができるため、初心者に適しています。 1)HTMLの学習曲線はスムーズで簡単に開始できます。 2)基本タグをマスターして、Webページの作成を開始します。 3)柔軟性が高く、CSSおよびJavaScriptと組み合わせて使用できます。 4)豊富な学習リソースと最新のツールは、学習プロセスをサポートしています。

Anexampleapalofastartingtaginhtmlis、それはaperginsaparagraph.startingtagsaresentionentientiontheyinitiateelements、definetheirtypes、およびarecrucialforurturingwebpagesandcontingthomedomを構築します。

メニューで点線のラインセグメンテーション効果を設計する方法は?メニューを設計するときは、通常、皿の名前と価格の間に左右に合わせることは難しくありませんが、真ん中の点線またはポイントはどうですか...


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

WebStorm Mac版
便利なJavaScript開発ツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

メモ帳++7.3.1
使いやすく無料のコードエディター
