转载---JQuery 对 Select option 的操作
下拉框:
<select id="selectID" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
下面是对下拉框的基本操作:
<script language="javascript">
$(document).ready(function() {
//绑定下拉框change事件,当下来框改变时调用 SelectChange()方法
$("#selectID").change(function() { SelectChange(); });
})
function SelectChange() {
//获取下拉框选中项的text属性值
var selectText = $("#selectID").find("option:selected").text();
alert(selectText);
//获取下拉框选中项的value属性值
var selectValue = $("#selectID").val();
alert(selectValue);
//获取下拉框选中项的index属性值
var selectIndex = $("#selectID").get(0).selectedIndex;
alert(selectIndex);
////获取下拉框最大的index属性值
var selectMaxIndex = $("#selectID option:last").attr("index");
alert(selectMaxIndex);
} function aa() {
//设置下拉框index属性为5的选项 选中
$("#selectID").get(0).selectedIndex = 5;
}
function bb() {
//设置下拉框value属性为4的选项 选中
$("#selectID").val(4);
}
function cc() {
//设置下拉框text属性为5的选项 选中
$("#selectID option[text=5]").attr("selected", "selected"); $("#yyt option:contains('')").attr("selected", true); }
function dd() {
//在下拉框最后添加一个选项
$("#selectID").append("<option value='7'>7</option>");
}
function ee() {
//在下拉框最前添加一个选项
$("#selectID").prepend("<option value='0'>0</option>")
}
function ff() {
//移除下拉框最后一个选项
$("#selectID option:last").remove();
} function gg() {
//移除下拉框 index属性为1的选项
$("#selectID option[index=1]").remove();
} function hh() {
//移除下拉框 value属性为4的选项
$("#selectID option[value=4]").remove();
}
function ii() {
//移除下拉框 text属性为5的选项
$("#selectID option[text=5]").remove();
}
</script>
转载---JQuery 对 Select option 的操作的更多相关文章
- JQuery 对 Select option 的操作---转载
<select id="selectID" > <option value="1">1</option> <optio ...
- JQuery 对 Select option 的操作
下拉框: <select id="selectID" > <option value="1">1</option& ...
- (网页)JQuery 对 Select option 的操作(转)
转自博客园: <select id="selectID" > <option value="1">1</option> &l ...
- Jquery获取select option动态添加自定义属性值失效
Jquery获取select option动态添加自定义属性值失效 2014/12/31 11:49:19 中国学网转载 编辑:李强 http://www.xue163.com/588880/3909 ...
- jquery获得select option的值和对select option的操作
<body> <select name="month" id="selMonth" onchange="set()"> ...
- jquery获得select option的值 和对select option的操作
jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Se ...
- jquery获得select option的值 和对select option的操作【转藏】
获取Select : 获取select 选中的 text : $("#ddlRegType").find("option:selected").text(); ...
- jquery 对select option 增删改查
一.查 jQuery获取select的Text和Value: 代码如下: 1.当select添加选择事件,当选择其中一项时触发: $("#select_id"). ...
- JS & JQuery 动态处理select option
原文 出处http://www.51xuediannao.com/html+css/htmlcssjq/cssbuhuanhang.html 今天你问了我一个关于在<select>里动态添 ...
随机推荐
- Python中的变量作用域
python中变量作用域包括: L (Local) 局部作用域,函数内部声明但没有使用global的变量E (Enclosing) 闭包函数外的函数中,def或者lambda的本地作用域G (Glob ...
- flume实现kafka到文件测试用例
kafka 到 file at2.sources =st2 at2.channels = ct2 at2.sinks = kt2 # For each one of the sources, the ...
- 我的代码-sql query
# coding: utf-8 # In[ ]: WITH List AS (SELECT e.*,f.* FROM( SELECT DISTINCT c.lot_id, c.wafer_key,LE ...
- PTA——出现次数最多的数
PTA 7-58 求整数序列中出现次数最多的数 #include<stdio.h> #define N 1000 int main() { ,flag; ]; scanf("%d ...
- VS2017 C/C++输入密码显示*星号
VS2017 C/C++输入密码显示*星号 _getch()函数使用时遇到的坑 参考: https://blog.csdn.net/guin_guo/article/details/46237905 ...
- python bif
filter(过滤器): 语法: filter(function, iterable) funciton 为判断函数 iterable 为可迭代对象 ...
- 用vs2010打开使用vs2013升级后的WP工程
项目在win7+vs2010的环境中建立的,后来在win8.1+vs2013的环境下修改和完善: 但是所有功能实现后发现wp7项目在使用vs2013打开后因为单向升级的原因,项目只能被编译为wp8项目 ...
- Salesforce Lightning Builder Flows (Salesforce Lightning 构建Flows)
本文构建Salesforce Lightning Flows 只是一个简单的实现步骤,原文地址如下: https://trailhead.salesforce.com/en/content/learn ...
- 百度ip定位城市接口调用
http://lbsyun.baidu.com/index.php?title=webapi/ip-api require 'rubygems' require 'json' print ARGV p ...
- linux系统如何发送邮件
安装应用yum install mailx sendmail -y接着修改/etc/mail.rc文件,添加一下参数#末尾添加 zabbix 发送告警信息邮箱(按照自己的情况修改)set from= ...