Home > Article > Web Front-end > JQuery implementation code to add/delete nodes to select
The following editor will bring you an implementation code of JQuery to add/delete nodes to select. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference
jQuery to get the Text and Value selected by Select:
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 adds/removes the Option item of Select:
jQuery("#select_id").append(""); //为Select追加一个Option(下拉项) jQuery("#select_id").prepend(""); //为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
Clear the content:
jQuery("#select_id").empty();
The above is the entire content of the implementation code for JQuery to add/delete nodes to select. I hope it can give everyone a reference.