Home > Web Front-end > JS Tutorial > body text

JQuery operation on Select option

巴扎黑
Release: 2017-06-29 10:02:40
Original
1005 people have browsed it

下拉框:


<select id="selectID" >
        
<option value="1">1option>
        
<option value="2">2option>
        
<option value="3">3option>
        
<option value="4">4option>
        
<option value="5">5option>
        
<option value="6">6option>
    
select>

 

 

 下面是对下拉框的基本操作:

 


<#script language="javascript ">
                                                                                                                             //Bind the drop-down box change
event
, and call the SelectChange() method when the drop-down box changes"
#selectID
").change(function() { SelectChange(); }); SelectChange() {       //Get the text attribute
value of the selected item in the drop-down box

# # var selectText = $("
#selectID").find( "option:selected").text();         alert(selectText);           //Get the value attribute of the selected item in the drop-down box
## var selectValue
= $ ("
#selectID
").val();       alert(selectValue);           //Get the index attribute value of the selected item in the drop-down box## var selectIndex

=
$ ("#selectID
").get(0).selectedIndex; alert(selectIndex); ////Get the maximum index attribute value of the drop-down box var selectMaxIndex

=
$("#selectID option:last
").attr("index"); alert(selectMaxIndex) ; } function aa() { ##       $("#selectID").get(0).selectedIndex = 5;
}
       function bb()                                                                                                                                  (
"#selectID"
).val(
4); }   function cc() {         // Set the option of setting the text attribute of the drop-down box to 5 and select

        $(
"#selectID option[text=5]"
).attr(
"selected", "selected");").attr("

selected

",

true

);

}
function dd() {
 
//Add an option at the end of the drop-down box
       $("#selectID").append("");
}
function ee() {
      
//Add an option at the front of the drop-down box
##                                                      ##selectID").prepend("

The above is the detailed content of JQuery operation on Select option. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!