Home > Web Front-end > JS Tutorial > Jquery operation select

Jquery operation select

巴扎黑
Release: 2017-06-29 10:09:45
Original
932 people have browsed it

1. Determine whether there is an Item with Value="paraValue" in the select option
$("#selectid option[@value='paraValue']").length>0
2. Add an Item
$("#selectid").append("

7.Set the item in select An Item is selected

$("#selectid option").eq(0).attr('selected', 'true');

8. Get the selected The value of the currently selected item

$("#selectid").val();
9. Get the text of the currently selected item of select
$( "#selectid").text();
10. Get the Index of the currently selected item of select

document.getElementById("select1").selectedIndex;$("#selectid").get(0).selectedIndex
11. Clear the selected item
$("#selectid").empty();

JS version:


  • //1. Determine whether there is an Item with Value="paraValue" in the select option

  • ##function jsSelectIsExitItem(objSelect,objItemValue)

  • {
  • var isExit = false ;

  • for ( var i=0;i;I++)

  • #                                                                
  •                                                                    

  •                                                                                                                                                                                                                                ##break##;

  • ##                                                                                                                                                                                      isExit; }

  • ##//2. Add an Item

    to the select option
  • function jsAddItemToSelect(objSelect, objItemText,objItemValue, objItemPos) {

  • ##//Judge whether it exists

  • ##if

  • (jsSelectIsExitItem(objSelect,objItemValue))
  • { alert(

  • "The Value of this Item already exists"

  • );
  • ## }

  • else ## {

  • var varItem =

  • new
  • Option(objItemText,objItemValue);
  • //               objSelect.options[objSelect.options.length] = varItem; add(varItem, objItemPos); alert( "Joined successfully"

  • );

  • }  

    }   # #//3. Delete an Item from the select option

  • ##function jsRemoveItemFromSelect(objSelect,objItemValue)

  • {

  • //Judge whether it exists

  • if

  • (jsSelectIsExitItem(objSelect,objItemValue) )

  • {

  •         for ( var i=0;i;I++)

  • {

  • ##if (objSelect.options[i].value == objItemValue)

  • ##                                                                                                                                           ##; ##"Successfully deleted"
  • );
  • }
  • else

  • {
  • alert(
  • "This item does not exist in the selection" );

    }  
  • ##}  

  • //4. Modify the text of value="paraValue" in the select option to "paraText"

  • ##function
  • jsUpdateItemToSelect(objSelect, objItemText,objItemValue)

  • {
  • //Judge whether it exists

  • ##if

  • (jsSelectIsExitItem(objSelect,objItemValue))
  •                                                    #var

    i=0;i;I++)
  •                                                      
  •        

    if

    (objSelect.options[i].value == objItemValue)
  • {# Objselect.options [i] .text = objitemtext; #break

  • ;
  • }

  • #}

  • # Alert ( ## "Successful modification" );

  • # {
  • alert( "This select This item does not exist in " );

  • }

  • }

  • //5. Set the first Item with text="paraText" in the select to be selected

  • ##function

  • jsSelectItemByValue(objSelect,objItemText)

    { ​

  •  ​

    //Determine whether it exists

  •  ​

  • var

    isExit =

    false
  • ; for (

    var
  • i=0;i;I++) ## { if (objSelect.options[i].text == objItemText)

  • # Objselect.options [i] .select =
  • ## True ; #                                                                                                                                                                                                                                                                                                  because

    break
  • ;
  • } ## }  

  • //Show the results

    ##if
  • (isExit) {

    alert (
  • "Successfully selected"

  • );
  •                                                                                                                                                   alert( "This item does not exist in this selection"

    );
  • }  
  • }  

  • ##//6. Set the Item with value="paraValue" in select to be selected

  • ##document.all.objSelect.value = objItemValue;

  • ##///7. Get the value of the currently selected item of select

  • var


  • currSelectValue = document.all.objSelect.value;
  • //8. Get the text of the currently selected item of select

  • var


  • currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;
  • //9. Get the Index of the currently selected item of select

  • var


  • currSelectIndex = document.all.objSelect.selectedIndex;
  • //10. Clear the selected items ##document.all.objSelect.options.length = 0 ;


The above is the detailed content of Jquery operation select. 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