1  select 获取和设置值,以及onchange事件

1下拉框option没有checked事件 可通过select 的 onchange事件进行监控,以获取其值

<select name="myselect" id="myselect">
<option value="opt1">选项1</option>
<option value="opt2">选项2</option>
<option value="opt3">选项3</option>
</select> $("#myselect").change(function(){
var opt=$("#myselect").val();
...
});

 2 普通的设置以及获取值

<select name="width" id="selectW">
<option value="50%">50%</option>
<option value="100%">100%</option>
</select> 在js中
1:var options=$("#test option:selected"); //获取选中的项
alert(options.val()); //拿到选中项的值
alert(options.text());
2:$("#selectW").find("option:selected").text();//选中的文本
3:$('#selectW option[value="100%"]').attr('selected',true);//设置某个值被选中
4:$(".selector").find("option:selected").text();
5:$(".selector").find("option[text='pxx']").attr("selected",true);
//(obj.someTime = '12:00-13:00'类似的值的时候)
$('#orderTime').val(''+obj.orderTime);
$('#orderTime').find('option[value="'+obj.orderTime+'"]').attr('selected',true);
$('#orderTime option[value="'+obj.orderTime+'"]').attr('selected',true);
注意:input的单选多选按钮是checked 详见下面的介绍;

2 checkbox的赋值和取值 

1. 获取单个checkbox选中项(三种写法):

$("input:checkbox:checked").val()
//或者
$("input:[type='checkbox']:checked").val();
//或者
$("input:[name='ck']:checked").val();

2. 获取多个checkbox选中项:

$('input:checkbox').each(function() {
if ($(this).attr('checked') ==true) {
alert($(this).val());
}
});

3. 设置第一个checkbox 为选中值:

$('input:checkbox:first').attr("checked",'checked');
$('input:checkbox').eq(0).attr("checked",'true');

4. 设置最后一个checkbox为选中值:

$('input:radio:last').attr('checked', 'checked');
$('input:radio:last').attr('checked', 'true');

5. 根据索引值设置任意一个checkbox为选中值:

$('input:checkbox).eq(索引值).attr('checked', 'true');索引值=0,1,2....
$('input:radio').slice(1,2).attr('checked', 'true');  

6. 选中多个checkbox: 
同时选中第1个和第2个的checkbox:

$('input:radio').slice(0,2).attr('checked','true'); 

7. 根据Value值设置checkbox为选中值:

$("input:checkbox[value='1']").attr('checked','true');

8. 删除Value=1的checkbox:

$("input:checkbox[value='1']").remove();

9. 删除第几个checkbox:

$("input:checkbox").eq(索引值).remove();索引值=0,1,2....
//如删除第3个checkbox:
$("input:checkbox").eq(2).remove();

10.遍历checkbox:

$('input:checkbox').each(function (index, domEle) {
  //写入代码
});

11.全部选中

$('input:checkbox').each(function() {
$(this).attr('checked', true);
});

12.全部取消选择:

$('input:checkbox').each(function () {
$(this).attr('checked',false);
});

  

input 的radio checkbox 和 select 相关操作的更多相关文章

  1. JQuery对CheckBox的一些相关操作

    一.通过选择器选取CheckBox: 1.给CheckBox设置一个id属性,通过id选择器选取: <input type="checkbox" name="myB ...

  2. jQuery的select相关操作

    例: <select class="selector" id="selector"></select> 1.设置value为pxx的项选 ...

  3. Jquery常用操作:checkbox、select取值,radio、checkbox、select选中及其相关

    常用Jquery操作:checkbox取值.select取值.radio选中.checkbox选中.select选中及其相关: 1.影藏页面元素 使用jquery真的很方便,比如要控制div的显示与隐 ...

  4. [转]jQuery操作radio、checkbox、select 集合.

    1.radio:单选框 html代码 <input type="radio" name="radio" id="radio1" val ...

  5. checkbox,radio,selected相关操作

    1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...

  6. jQuery操作radio、checkbox、select 集合

    1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...

  7. jQuery操作radio、checkbox、select总结

    1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...

  8. JS中Float类型加减乘除 修复 JQ 操作 radio、checkbox 、select LINQ to SQL:Where、Select/Distinct LINQ to SQL Count/Sum/Min/Max/Avg Join

    JS中Float类型加减乘除 修复   MXS&Vincene  ─╄OvЁ  &0000027─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄Ov ...

  9. jquery radio、 checkbox、 select 操作

    转载:http://www.haorooms.com/post/checkandselect $("input[id^='code']");//id属性以code开始的所有inpu ...

随机推荐

  1. vue 动态绑定背景图片

    html <div class="racetm" :style="{backgroundImage: 'url(' + (coverImgUrl ? coverIm ...

  2. Redis cluster集群:原理及搭建

    Redis cluster集群:原理及搭建 2018年03月19日 16:00:55 阅读数:6120 1.为什么使用redis? redis是一种典型的no-sql 即非关系数据库 像python的 ...

  3. Dotfuscator代码混淆工具的使用

    关于Dotfuscator,VS自带了一个社区版的源代码保护工具,不过它只有基本的混淆命名的功能.专业版功能很多,可以混淆流程,密字符串,加入水印,程序签名等. 工具/原料   Dotfuscator ...

  4. 邮件收取客户端LumiSoft类库接收yahoo邮件的问题。

    //开始循环取邮件数据 m_pImap.Fetch( false, IMAP_t_SeqSet.Parse("1:*"), new IMAP_t_Fetch_i[]{ new IM ...

  5. 9.用js制作静态分页

    效果如图: css 代码: #page { text-align: center; } .page { display: inline-block; } .page a { padding: 3px ...

  6. C# dataGridView 如何选中整行?

    this.dataGridView1.SelectionMode =DataGridViewSelectionMode.FullRowSelect; dataGridView1即你的dataGridV ...

  7. 【Spring学习笔记-MVC】Spring MVC之多文件上传 (zhan)

    http://www.cnblogs.com/ssslinppp/p/4607330.html (zhan)

  8. TP增删改

    增加数据 <?php namespace Home\Controller; use Think\Controller; class IndexController extends Control ...

  9. 深入解析Java反射(1) - 基础

    深入解析Java反射(1) - 基础 最近正筹备Samsara框架的开发,而其中的IOC部分非常依靠反射,因此趁这个机会来总结一下关于Java反射的一些知识.本篇为基本篇,基于JDK 1.8. 一.回 ...

  10. ubuntu安装rvm

    sudo apt-get install curl git-core bash -s stable < <(curl -s https://raw.github.com/wayneeseg ...