1.page
<div>
<select name="album" id="album">
<option value="1">推荐</option>
<option value="2">排行</option>
<option value="3">分类</option>
<option value="4">搜索</option>
</select>
<div>
2.scripts
<script language="javascript" type="text/javascript" src="jquery-1.8.0.js"></script>
<script language="javascript" type="text/javascript" >
$(function(){
console.log("jquery do select");
$s = $("#album");
console.log($s);
//获取选项的value
console.log($s.val());
//获取选项的text
console.log($s.find("option:selected").text());
//清空
console.log("before clear size is "+$s.find("option").size());
$s.empty();
console.log("after clear size is "+$s.find("option").size());
//遍历追加
var ops = [{"v":1,"t":"推荐"},{"v":2,"t":"排行"},{"v":3,"t":"分类"},{"v":4,"t":"搜索"},{"v":5,"t":"我"}];
$(ops).each(function(i){
//添加下拉框的option
$("<option value="+this.v+">"+this.t+"</option>").appendTo($s);
});
//判断是否有选中项
console.log("选中项个数:"+$s.find("option[selected='selected']").size());
//遍历修改,把value+10
$s.find("option").each(function(i){
var $this = $(this);
var v = $this.val();
var t = $this.text();
//移除value=5的option
if(v==5){
$this.remove();
}
//对数字value增10,对text增+
if(!isNaN(v)){
$this.val(parseInt(v)+10);
$this.text(t+"+");
}
console.log($this.val());
});
//
});
</script>
相关推荐
举例说明如何通过JQuery操作select
NULL 博文链接:https://effort-fan.iteye.com/blog/1214681
Jquery操作select标签:包含选中、更改选中;获取选中option的text值、value值和ndex索引值;标签的清空、删除和增加等。
Jquery中对下拉框的操作 包括选中 赋值等
这个文档是本人在开发学习中下的别人的资料,觉得汇总的很好,后面在工作过程中修改了一些,非常有用,尤其是前端的,基本上对select option的操作都在这里面了。有收藏价值。
使用Selenium自带的API操作Select元素时页面可能出现上移或遮挡,导致元素操作失败; 介于此问题,可以使用JQuery来操作Select元素,具体实现见附件。
主要介绍了jquery操作select常见方法,结合实例形式总结分析了jQuery操作select常见的7种情况与相关操作技巧,需要的朋友可以参考下
jquery实现select下拉框的取值与赋值,设置选中的方法大全。 比如<select class=”selector”></select> 1、设置value为pxx的项选中 $(“.selector”).val(“pxx”); 2、设置text为pxx的项选中 $(“....
每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了。 比如<select class=”selector”></select> 1、设置value为pxx的项选中 $(“.selector”).val(“pxx”); 2、设置...
本文实例汇总了jquery操作select的方法。分享给大家供大家参考。具体如下: jQuery获取Select选择的Text和Value: 语法解释: 代码如下:$(“#select_id”).change(function(){//code…});//为Select添加事件,当...
jQuery Air 用户管理界面应用插件,类似于我们以前讲到的jquery select的操作例子,点上面的all复选框后,下面的选项即可进行操作并保存。由于是在国外网站获取的源码,界面没有汉化,所以只能给大家一个灵感,学习...
。
。
主要介绍了jquery下拉select控件操作方法分享(jquery操作select),需要的朋友可以参考下
NULL 博文链接:https://bijian1013.iteye.com/blog/2303003
主要介绍了jquery操作select中使用到的方法和示例,需要的朋友可以参考下
NULL 博文链接:https://wasabi.iteye.com/blog/260526