---
title: "select jquery 操作"
author: "mailx8"
date: "2017-01-17T11:51:14Z"
tags: []
categories: ["Web前端"]
slug: "select-jquery"
draft: false
lastmod: "2017-01-17T11:51:14Z"
id: 2353445
url: "https://mailx8.iteye.com/blog/2353445"
---

&lt;select id="selectID" &gt;

        &lt;option value="1"&gt;1&lt;/option&gt;

        &lt;option value="2"&gt;2&lt;/option&gt;

        &lt;option value="3"&gt;3&lt;/option&gt;

        &lt;option value="4"&gt;4&lt;/option&gt;

        &lt;option value="aa" index="5"&gt;ac5&lt;/option&gt;

        &lt;option value="6"&gt;6&lt;/option&gt;

    &lt;/select&gt;

选中select中的值

$("select option\[value='"+value+"']").attr("selected", "selected");

选中第n个

$(".selectinput option").eq(2).attr("selected",true);

值或内容中涵有china

$("#selectID option:contains('china')").attr("selected",true)

设置第5个选中 

$("#selectID").val(4);

设置第6个选中

$("#selectID").get(0).selectedIndex = 5; 

添加到最后,最前

$("#selectID").append("&lt;option value='7'&gt;7&lt;/option&gt;");

$("#selectID").prepend("&lt;option value='0'&gt;0&lt;/option&gt;")

//移除下拉框最后一个选项

$("#selectID option:last").remove();

//移除下拉框 index属性为5的选项  index为属性

$("#selectID option\[index=5]").remove();

 

select 选中,添加,删除..