jQuery对下拉框、单选框、多选框的处理
下拉框:
//得到下拉菜单的选中项的文本(注意中间有空格)
var cc1 = $(".formc select[@name='country'] option[@selected]").text(); //得到下拉菜单的选中项的值
var cc2 = $('.formc select[@name="country"]').val(); //得到下拉菜单的选中项的ID属性值
var cc3 = $('.formc select[@name="country"]').attr("id"); //清空下拉框//
$("#select").empty();$("#select").html(''); //添加下拉框的option
$("<option value='1'>1111</option>").appendTo("#select")
单选框:
//得到单选框的选中项的值(注意中间没有空格)
$("input[@type=radio][@checked]").val(); //设置单选框value=2的为选中状态.(注意中间没有空格)
$("input[@type=radio][@value=2]").attr("checked",'checked');
复选框:
//得到复选框的选中的第一项的值
$("input[@type=checkbox][@checked]").val(); //由于复选框一般选中的是多个,所以可以循环输出
$("input[@type=checkbox][@checked]").each(function(){
alert($(this).val());
}); //不打勾
$("#chk1").attr("checked",''); //打勾
$("#chk2").attr("checked",true); //判断是否已经打勾
if($("#chk1").attr('checked')==undefined){}
jQuery对下拉框、单选框、多选框的处理的更多相关文章
- 下拉选择select和复选框checkbox的状态的各种方式
复选框的状态 <input name="ck" value=" " type="checkbox" checked> 或者&l ...
- jquery div 下拉框焦点事件
这章与上一张<jquery input 下拉框(模拟select控件)焦点事件>类似 这章讲述div的焦点事件如何使用 div的焦点事件与input的焦点事件区别在于 需要多添加一个属性: ...
- Jquery操作下拉框(DropDownList)实现取值赋值
Jquery操作下拉框(DropDownList)想必大家都有所接触吧,下面与大家分享下对DropDownList进行取值赋值的实现代码 1. 获取选中项: 获取选中项的Value值: $('sele ...
- jquery 获取下拉框值与select text
下面先介绍了很多jquery获取select属性的方法,同时后面的实例我们讲的是jquery 获取下拉框值与select text代码. 下面先介绍了很多jquery获取select属性的方法,同时后 ...
- jQuery对下拉框Select操作总结
jQuery对下拉框Select操作总结 转自网络,留做备用 jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change( ...
- js,jquery获取下拉框选中的option
js获取select选中的值: var sel=document.getElementById("select1"); var index = sel.selectedIndex; ...
- Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢)
Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢) 1. 获取选中项: 获取选中项的Value值: $('select#sel option:selected').val() ...
- ul+jquery自定义下拉选择框
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- jQuery操作下拉框的text值和val值
jQuery操作下拉框的text值和val值 1,JS源码 <select name="select1" id="select1" style=" ...
随机推荐
- Linux查看一个文件夹大小
1.Linux查看一个文件夹大小: du -sh /home/yangkun [yangkun@sg1 bin]$ du -sh /home/yangkun/ 164M /home/yangkun/ ...
- 转: pthread_create()
pthread_create函数 原型:int pthread_create((pthread_t *thread, pthread_attr_t *attr, void *(*start ...
- PHP 中的数组
PHP中的数组是指一个键/值对的集合.PHP中的数组是使用哈系表构建的,这意味着访问每一个值都会有一个平均的O(1)复杂度. $arr=array([key=>]value,....); 在这里 ...
- NUnit+mock+moq单元测试
[TestFixture] public class InstantBatchBuyTest { private string _mallAbc; private string _itemCode; ...
- Cracking the coding interview--Q1.2
原文 Implement a function void reverse(char* str) in C or C++ which reverses a null-terminated string. ...
- MCS-51单片机的指令时序
时序是用定时单位来描述的,MCS-51的时序单位有四个,它们分别是节拍.状态.机器周期和指令周期,接下来我们分别加以说明. 节拍与状态: 我们把振荡脉冲的周期定义为节拍(为方便描述,用P表示), ...
- 【转】如何在 Android 程序中禁止屏幕旋转和重启Activity
原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...
- HDU_2051——十进制到二进制转换
Problem Description Give you a number on base ten,you should output it on base two.(0 < n < 10 ...
- HDU-4857(拓扑排序)
Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必须在b之前. ...
- HDU-3661(贪心)
Problem Description In a factory, there are N workers to finish two types of tasks (A and B). Each t ...