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

jQuery gets the text and value selected by select

巴扎黑
Release: 2017-06-29 10:05:49
Original
2316 people have browsed it

jqueryGet the text and value selected by select
Get select:
Get select selected text:
$("#ddlregtype").find("option:selected").text() ;

Get the value selected by select:
$("# ddlregtype ").val();
Get the
index selected by select:
$("#ddlregtype ").get(0).selectedindex;
Set select:
Set select selected index:

$("#ddlregtype ").get(0).selectedindex=index;//index is the index value
Set select selected value:

$("#ddlregtype ").attr("value","normal");    $("#ddlregtype ").val("normal");
    $("#ddlregtype ").get(0).value = value;

设置select 选中的text:

    var count=$("#ddlregtype option").length;
      for(var i=0;i
         {           if($("#ddlregtype ").get(0).options[i].text == text)
            {
                $("#ddlregtype ").get(0).options[i].selected = true;
                break;
            }
        }
    $("#select_id option[text='jquery']").attr("selected", true);

设置select option项:

    $("#select_id").append("");  //添加一项option
$("#select_id").prepend(""); //Insert an option
$("#select_id option:last").remove(); //Delete the option with the largest index value
$("#select_id option[index='0']").remove();//Delete option with index value 0

The above is the detailed content of jQuery gets the text and value selected by 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!