![jQuerySelect下拉框操作小結(jié)_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/29/f39b9826-6ffd-4598-8256-197008d282ce/f39b9826-6ffd-4598-8256-197008d282ce1.gif)
![jQuerySelect下拉框操作小結(jié)_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/29/f39b9826-6ffd-4598-8256-197008d282ce/f39b9826-6ffd-4598-8256-197008d282ce2.gif)
![jQuerySelect下拉框操作小結(jié)_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/29/f39b9826-6ffd-4598-8256-197008d282ce/f39b9826-6ffd-4598-8256-197008d282ce3.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、這篇文章主要介紹了jQuerySelectT拉框操作小結(jié)(推薦)的相關(guān)資料,非常實(shí)用,在前端開發(fā)經(jīng)??梢杂玫?,需要的朋友可以參考下jQuery獲取Select元素,并選擇的Text和Value:1. $("#select_id").change(function()/code.);/為Select添加事件,當(dāng)選擇其中一項(xiàng)時(shí)觸發(fā)2. varcheckText=$("#select_id").find("option:selected").text();/獲取Select選擇的Text3. varcheckValue=$("#s
2、elect_id").val();/獲取Select選擇的Value4. varcheckIndex=$("#select_id").get(0).selectedIndex;/獲取Select選擇的索引值5. varmaxIndex=$("#select_idoption:last").attr("index");/獲取Select最大的索引值jQuery獲取Select元素,并設(shè)置的Text和Value:實(shí)例分析:1. $("#select_id").get(0).selectedIndex=1;/設(shè)
3、置Select索引值為1的項(xiàng)選中2. $("#select_id").val(4);/設(shè)置Select的Value值為4的項(xiàng)選中3. $("#select_idoptiontext='jQuery'").attr("selected”,true);/設(shè)置Select的Text值為jQuery的項(xiàng)選中jQuery添加/刪除Select元素的Option項(xiàng):實(shí)例分析:1. $("#select_id").append("<optionvalue='Value'>
4、;Text</option>");/為Select追加一個(gè)Option(下拉項(xiàng))2. $("#select_id").prepend("<optionvalue='0'>請(qǐng)選擇</option>");/為Select插入一個(gè)Option(第一個(gè)位置)3. $("#select_idoption:last").remove();/刪除Select中索引值最大Option(最后一個(gè))4. $("#select_idopt
5、ionindex='0'").remove();/刪除Select中索引值為0的Option(第一個(gè))5. $("#select_idoptionvalue='3'").remove();/刪除Select中Value='3'的Option6. $("#select_idoptiontext='4'").remove();/刪除Select中Text='4'的Option三級(jí)分類<selectname="thirdLevel"id=
6、"thirdLevel"onchange="getFourthLevel()"><optionvalue="0"id="thirdOption">請(qǐng)選擇三級(jí)分類</option></select></div>四級(jí)分類:<selectname="fourthLevelId"id="fourthLevelId"><
7、optionvalue="0"id="fourthOption">請(qǐng)選擇四級(jí)分類</option></select></div>.if($("#thirdLevel").val()!=0)$("#thirdLeveloptionvalue!=0").remove();if($("#fourthLevelId").val()!=0)($("#fourthLevelIdoptionvalue!
8、=0").remove();這個(gè)表示:假如我們希望當(dāng)選擇選擇第三類時(shí):如果第四類中有數(shù)據(jù)則刪除,如果沒有數(shù)據(jù)第四類的商品中的為默認(rèn)值。在后面學(xué)習(xí)了AJAX技術(shù)后經(jīng)常會(huì)使用到!獲取Select:獲取select選中的text:$("#ddlRegType").find("option:selected").text();獲取select選中的value:$("#ddlRegType").val();獲取select選中的索引:$("#ddlRegType").get(0).selectedIndex;設(shè)置s
9、elect:設(shè)置select選中的索引:$("#ddlRegType").get(0).selectedIndex=index;/index為索引值設(shè)置select選中的value:$("#ddlRegType").attr("value”,"Normal“);$("#ddlRegType").val("Normal");$("#ddlRegType").get(0).value=value;設(shè)置select選中的text:varcount=$("#ddlRegTy
10、peoption").length;for(vari=0;i<count;i+)(if($("#ddlRegType").get(0).optionsi.text=text)($("#ddlRegType").get(0).optionsi.selected=true;break;$("#select_idoptiontext='jQuery'").attr("selected",true);設(shè)置selectoption項(xiàng):$("#select_id").
11、append("<optionvalue='Value'>Text</option>");/添加一項(xiàng)option$("#select_id").prepend("<optionvalue='0'>請(qǐng)選擇</option>");/在前面插入一項(xiàng)option$("#select_idoption:last").remove();/刪除索引值最大的Option$("#s
12、elect_idoptionindex='0'").remove();/刪除索引值為0的Option$("#select_idoptionvalue='3'").remove();/刪除值為3的Option$("#select_idoptiontext='4'").remove();/刪除TEXT值為4的Option清空Select:$("#ddlRegType").empty();jquery獲得值:.val().text()設(shè)置值.val('在這里設(shè)置值')
13、$("document").ready(function()($("#btn1").click(function()($("name='checkbox'").attr("checked”,'true');/全選)$("#btn2”).click(function()$("name='checkbox'").removeAttr("checked");/取消全選)$("#btn3”).click(function()$
14、("name='checkbox':even").attr("checked”,'true');/選中所有奇數(shù))$("#btn4”).click(function()$("name='checkbox'").each(function()/反選if($(this).attr("checked")$(this).removeAttr("checked");else$(this).attr("checked",'true');)$("#b
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年企業(yè)物料策劃供應(yīng)合同協(xié)議
- 2025年律師事務(wù)所服務(wù)協(xié)議標(biāo)準(zhǔn)文本
- 2025年通信電源項(xiàng)目申請(qǐng)報(bào)告模板
- 2025年穿水冷卻裝置項(xiàng)目提案報(bào)告
- 2025年住宅銷售經(jīng)紀(jì)服務(wù)協(xié)議
- 2025年市場(chǎng)準(zhǔn)入合規(guī)策劃合作框架協(xié)議
- 2025年企業(yè)簽訂網(wǎng)絡(luò)安全協(xié)議
- 2025年企業(yè)股東間保密協(xié)議策劃樣本
- 2025年實(shí)習(xí)生供求策劃協(xié)議書模板
- 2025年丹陽市美容院股東權(quán)益策劃與分配合同書
- 《學(xué)會(huì)積極歸因》教學(xué)設(shè)計(jì)
- 頸肩腰腿痛的注射治療課件整理-002
- 半導(dǎo)體溫度計(jì)設(shè)計(jì)與制作
- 八年級(jí)英語閱讀理解每日一練
- Q2起重機(jī)司機(jī)模擬考試100題(精選)
- 動(dòng)火作業(yè)安全管理要求及控制措施
- 制種玉米去玉米制種去雜去雄技術(shù)及質(zhì)量檢查
- 資源循環(huán)科學(xué)和工程專業(yè)建設(shè)探討
- 2023年河南省鄭州市一模道德與法治試題(含答案)
- 2023年湖南高速鐵路職業(yè)技術(shù)學(xué)院高職單招(語文)試題庫含答案解析
- FZ/T 54024-2019錦綸6預(yù)取向絲
評(píng)論
0/150
提交評(píng)論