Jquery 操作 select 的操作指南
这里我们以一个简单的select作为原型来进行说明:
<select>
<option value="a1">香蕉1</option>
<option value="a2">香蕉2</option>
<option value="a3">香蕉3</option>
<option value="a1">香蕉4</option>
<option value="a4">香蕉5</option>
<option value="a5">香蕉6</option>
<option value="a6" selected ="selected">香蕉7</option>
<option value="a7">香蕉8</option>
<option value="a8">香蕉9</option>
<option value="a9">香蕉0</option>
</select>
1.获取/设置当前option的value值
$('select').val(); //获取值
$('select').val('a8'); //设置值
2.获取/设置当前option的文本:注意:.find("option[text='.......']")适用于input标签,不适用与select标签
var text = $("select").find("option:selected").text(); //获取text
$("select").find("option:contains('香蕉4')").attr("selected",true); //设置当前option的text
3.获取/设置当前option的index:
var checkIndex=$("select").get(0).selectedIndex; //获取index
$("select").get(0).selectedIndex=2; //设置index,index从0开始计数
4.常见的添加/删除option操作:
1. $("select").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)
2. $("select").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)
3. $("select option:last").remove(); //删除Select中索引值最大Option(最后一个)
4. $("select option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)
5. $("select option[value='3']").remove(); //删除Select中Value='3'的Option
6. $("select option[text='4']").remove(); //删除Select中Text='4'的Option
Jquery 操作 select 的操作指南的更多相关文章
- Jquery操作select,左右移动,双击移动 取到所有option的值
$(function () { function MoveItem(fromId, toId) { $("#" + fromId + " option:selected& ...
- ThinkPHP第二十六天(JQuery操作select,SESSION和COOKIE)
1.JQuery操作select,假设<select id="my"> A:双击选项<option>事件,应该是select的dbclick事件. B:获得 ...
- jquery操作select下拉框的各种方法,获取选中项的值或文本,根据指定的值或文本选中select的option项等
简介jquery里对select进行各种操作的方法,如联动.取值.根据值或文本来选中指定的select下拉框指定的option选项,读取select选中项的值和文本等. 这一章,站长总结一下jquer ...
- js与jQuery操作select大全
Js操作Select是很常见的,也是比较实用的,每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了. 一.js操作select部分 判断select选项中 是否存在V ...
- Jquery 操作 Select 详解
jQuery是如何控制和操作select的.先看下面的代码 比如<select class="selector"></select> 1.设置value为p ...
- JQuery操作select下拉框
JQuery操作select下拉框 获取Select选择的Text和Value $("#select_id").change(function(){//code...}); //为 ...
- jquery 操作select 资料
每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了. 比如<select class="selector"></select&g ...
- jquery操作select(增加,删除,清空)
jQuery获取Select选择的Text和Value: $("#select_id").change(function(){//code...}); //为Select添加事件, ...
- Jquery操作select小结
每次操作select都要查资料,干脆总结一下. 为select设置placeholder <select class="form-control selOP" placeho ...
随机推荐
- Create a soft keyboard
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Csharp:WebClient and WebRequest use http download file
//Csharp:WebClient and WebRequest use http download file //20140318 塗聚文收錄 string filePath = "20 ...
- Nodejs学习笔记之复制文件
前端童鞋都知道,javascript是没有权限操作磁盘文件的,server童鞋一向都很鄙视.但是nodejs可谓让咱们前端扬眉吐气啊,最近在学node,其强大的功能让人异常激动和兴奋.今天就学习了它怎 ...
- 项目经验:GIS<MapWinGIS>建模第一天
随便记录下项目的进展情况: GIS平台系统,实现整个供水系统的协调与统一.系统以管网为基础依据,建立可实现供水管网规划设计.输配管理.图档管理.抢修辅助决策及综合查询.统计等功能. 本文档的预期读者是 ...
- 二、Flex 布局教程:实例篇
注:本文转自大神阮一峰,自己加了少许改动~ 上一篇文章介绍了Flex布局的语法,今天介绍常见布局的Flex写法. 你会看到,不管是什么布局,Flex往往都可以几行命令搞定. 我只列出代码,详细的语法解 ...
- SQL Server 使用 OUTPUT做数据操作记录
OUTPUT 子句 可以在数据进行增删改的时候,可以返回受影响的行.先准备一张表 create table #t ( id int identity primary key ,name ) ) go ...
- iOS文件处理类
iOS文件处理类 这是一个用来简化iOS中关于文件操作的一个类,所有方法都为类方法. Source File.h // // File.h // FileManager // // http://ho ...
- 用QT写一个对话框
打开QT creater创建取名去findDialog的项目,这个项目要基于QDialog.直接上FindDialog.h的头文件. #ifndef FINDDIALOG_H #define FIND ...
- WSDM 2014推荐系统论文
Xiao Yu, Hao Ma, Paul Hsu, Jiawei Han On Building Entity Recommender Systems Using User Click Log an ...
- Geekforgeek week1
1. is palindrome solution 1: check to reverse the digit, if they are the same number https://www.gee ...