DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> JQuery給元素添加/刪除節點比如select
JQuery給元素添加/刪除節點比如select
編輯:JQuery特效代碼     
jQuery獲取Select選擇的Text和Value:
. 代碼如下:
var checkText=jQuery("#select_id").find("option:selected").text(); //獲取Select選擇的Text
var checkValue=jQuery("#select_id").val(); //獲取Select選擇的option Value
var checkIndex=jQuery("#select_id ").get(0).selectedIndex; //獲取Select選擇的索引值
var maxIndex=jQuery("#select_id option:last").attr("index"); //獲取Select最大的索引值

jQuery添加/刪除Select的Option項
. 代碼如下:
jQuery("#select_id").append("<option value='Value'>Text</option>"); //為Select追加一個Option(下拉項)
jQuery("#select_id").prepend("<option value='0'>請選擇</option>"); //為Select插入一個Option(第一個位置)
jQuery("#select_id option:last").remove(); //刪除Select中索引值最大Option(最後一個)
jQuery("#select_id option[index='0']").remove(); //刪除Select中索引值為0的Option(第一個)
jQuery("#select_id option[value='3']").remove(); //刪除Select中Value='3'的Option
jQuery("#select_id option[text='4']").remove(); //刪除Select中Text='4'的Option

內容清空:
. 代碼如下:
jQuery("#select_id").empty();
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved