【jquery操作select取值赋值与设置选中实例】教程文章相关的互联网学习教程文章

jquery控制select的text/value值为选中状态

每一次操作select的时候,总是要在网上翻下,太繁琐了,自己在这里总结下。 比如<select class="selector"></select> 1、设置value为“全部“的项选中 代码如下:$(".selector").val("全部"); 2、设置text为“全部“的项选中 代码如下:$(".selector").find("option[text=全部]").attr("selected",true); 这里有一个中括号的用法,中括号里的等号的前面是属性名称,不用加引号。很多时候,中括号的运用可以使得逻辑变得很简单。 ...

jQuery操作select下拉框的text值和value值的方法

1、jquery获取当前选中select的text值 var checkText=$("#slc1").find("option:selected").text(); 2、jquery获取当前选中select的value值 var checkValue=$("#slc1").val(); 3、jquery获取当前选中select的索引值 var index=$("#slc1 ").get(0).selectedIndex; 4、jquery设置索引值为1的项为当前选中项 $("#slc1 ").get(0).selectedIndex=1; 5、jquery设置value值2的项为当前选中项 $("#slc1 ").val(2); 6、jquery设置text值为"青...

jquery通过select列表选择框对表格数据进行过滤示例

jquery通过select列表选择框对表格数据进行过滤 表格数据 代码如下:<table id="example"> <thead> <tr> <th>Name</th> <th>Surname</th> </tr> </thead> <tbody> <tr> <td>Michael</td> <td>Jordan</td> </tr> <tr> <td>Michael</td> <td>Jackson</td> </tr> <tr> <td>Bruno</td> ...

jquery实现select选中行、列合计示例

Jquery 方法 代码如下:$( function () { //页面加载时计算人员统计表合计值 calcSum(); }); //合计行计算 /* 以合计行为中间变量 每个单元格与该列合计行相加 得到每列合计 */ function trVisible(chk, index) { var disValue = $("#Tr" + index).css("display"); if (chk.checked) { $("#Tr" + index).css("display", "block"); } else { $("#Tr" + index).css("display", "none"); } calcSum(); } function calcSum() { //合计行...

jquery下拉select控件操作方法分享(jquery操作select)

JQuery获取和设置Select选项方法汇总如下: 代码:代码如下:$("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Textvar checkValue=$("#select_id").val(); //获取Select选择的Valuevar checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值var maxIndex=$("#select_id op...

jquery 操作两个select实现值之间的互相传递

代码如下:function moveToRight(select1,select2)//把选中的移动到右边 sleect1和sleect2分别是下拉列表框的ID{ $('#'+select1+' option:selected').each(function(){ $("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select2+""); $(this).remove(); $('#'+select2).bind('dblclick',function(){ moveToLeft(select1,select2); }); });}function moveAllToRight(select1,select2)//把所...

jquery取消选择select下拉框示例代码

有三个select下拉框一个大类,两个小类隐藏,需要在选择大类的时候,小类显示同时清除另外的小类选择的项这需求有点儿.......... 下面是三个select: 代码如下:<select name="pWaqqqy" id="sel_type" onchange="selectFunction()"> <option value="">全部</option> <option value="7">aa</option> <option value="8">bb</option> </select> <select name="pWay" id="sel_children0" style="display:none;">...

jquery实现省市select下拉框的替换(示例代码)

省市对应的实现:<还有一些没封装起来> 更具选择的省份来确定市的内容 jsp代码: 代码如下:<body> 省份<select name="prin"> <option>--请选择--</option> <option>福建</option> <option>北京</option> <option>山东</option> <option>上海</option> </select> 县、市<select id="sel2"> <option>--请选择--</option> </select> </body>js代码: 代码如下:function appendShi(shi) {//字符串拼接,拼接...

jquery select 设置默认选中的示例代码

代码如下: 其中<%=selectedvalue %>为从后台获取的值 $(document).ready(function(){ $("#seltype").attr("value",parseInt(<%=selectedvalue %>)); })

jquery操作select详解(取值,设置选中)

每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了。 比如<select class="selector"></select> 1、设置value为pxx的项选中 $(".selector").val("pxx"); 2、设置text为pxx的项选中 $(".selector").find("option[text=pxx]").attr("selected",true); 这里有一个中括号的用法,中括号里的等号的前面是属性名称,不用加引号。很多时候,中括号的运用可以使得逻辑变得很简单。 3、获取当前选中项的valu...

JQUERY 设置SELECT选中项代码

JQUERY可通过value值,设定指定value的option为选中项 代码如下:$("#SelectId").attr("value", "theValueYouWantToSetIndex")另:jQuery.trim( str )方法,可以去掉字符串前后的空格

用jQuery模拟select下拉框的简单示例代码

很多时候,美工会觉得默认的select下拉框很难看(特别是右侧的下拉箭头按钮),他们通常喜欢用一个自定义的图标来代替这个按钮。这样就只能用 js + div 来模拟了,倒腾了一番,用jQuery模拟了下,当然网上这种文章也不少,只是懒得去看找 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>...

基于JQuery实现的Select级联

代码如下:$(document).ready(function(){ $("#precinct").change(function(){ $("#ptype").val("");//重置所有 $("#stype").html(""); $("#stype").append("<option value=\"\">--请选择--</option>"); }); <span style="white-space:pre"> </span>//监听专利类型change事件 $("#ptype").change(function(){ var ptype = $(this); var atype = $(this).val();//对象值 var pid = $("#precinct").val(); if (!ptype.data(atype)) {/...

jQuery:delegate中select()不起作用的解决方法(实例讲解)

jQuery有一个很好用的delegate(事件委派)功能,可以给当前以及将来(动态添加)的元素绑定一个事件处理函数。 比如下面的例子,动态添加一个输入文本框后,我想让所有文本框(不管是不是动态添加的)在获取焦点时,自动转大写。 代码如下:<!doctype html><html><head> <title>delegate测试</title> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.js"></script> <style type="text/css">...

JS,Jquery获取select,dropdownlist,checkbox下拉列表框的值(示例代码)

jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text 3. var checkValue=$("#select_id").val(); //获取Select选择的Value 4. var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值 5. var maxIndex=$("#se...

赋值 - 相关标签