获取input type=radio属性的value值
个人代码1:
<div class="form-group" style="width: 250px;margin:0 auto;">
<label for="">性别</label>
<input type="radio" id="driverSex" name="driverSex" value="男"/>男
<input type="radio" id="driverSex" name="driverSex" value="女"/>女
</div>
注意: 1.value属性不要写错,写错或没写会获取的值默认是on
2.name 属性必须一致
个人代码2:
//编辑
function editdriver(id) {
$.ajax({
url:"${pageContext.request.contextPath}/upadatedriver",
type:"GET",
data:{"id":id},
success:function(result){
console.log(result);
$("input[name=driverSex]").val([result.driverSex]);//回显性别
}
});
$("#driver").modal("show");//打开模态框
}
其他参考:
1.获取选中值,三种方法都可以:
$('input:radio:checked').val();
$("input[type='radio']:checked").val();
$("input[name='rd']:checked").val();
2.设置第一个Radio为选中值:
$('input:radio:first').attr('checked', 'checked');
或者
$('input:radio:first').attr('checked', 'true');
注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)
3.设置最后一个Radio为选中值:
$('input:radio:last').attr('checked', 'checked');
或者
$('input:radio:last').attr('checked', 'true');
4.根据索引值设置任意一个radio为选中值:
$('input:radio').eq(索引值).attr('checked', 'true');索引值=0,1,2....
获取input type=radio属性的value值的更多相关文章
- 获取<input type="radio">被选中的内容
背景: <input type="radio">,该标签表示的是单选按钮,这个类型相对于其他类型的获取,比较特殊,特此记录一下. 获取方式: 1. 使用选择器直接获取( ...
- jquery 获取 input type radio checked的元素
.find('input:radio:checked'):.find("input[type='radio']:checked");.find("input[name=' ...
- <input type="radio" >与<input type="checkbox">值得获取
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- 工作总结 js 选择器选择多条元素 支持一起设置他们属性 $("#edumes input[type='radio']").prop("checked", false);
$("#edumes input[type='radio']").prop("checked", false); $("#edumes input[t ...
- jQuery操作<input type="radio">
input type="radio">如下: <input type="radio" name="city" value=&qu ...
- asp.mvc获取checkbox、radio、select的值
记录一下在asp.mvc中,提交表单时后台获取checkbox.radio.select值的方法. 1.获取select的值 <select name="type"> ...
- jquery attr方法和prop方法获取input的checked属性问题
jquery attr方法和prop方法获取input的checked属性问题 问题:经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法 ...
- 获取input type=file 的文件内容(纯文本)
一.获取input type=file 的文件内容(纯文本) 1.需求一 通过点击其他事件,来触发 文件选择框(限定格式为 .c 文件),而不是手动鼠标点击触发. [思路:] step1:将 inpu ...
- Jquery给input[type=radio] 控件赋值
setobject: function (data, scope, win) { //data jsoon数据, scope,一般为form的id,win 窗口对象,如果在当前window win=n ...
随机推荐
- util之Set
1.定义: Set<Integer>set = new TreeSet<Integer>(); 注意: TreeSet 是二差树实现的,Treeset中的数据是自动排好序的,不 ...
- layui下拉框数据过万渲染渲染问题解决方案
方案一:layui下拉框分页插件 https://fly.layui.com/jie/29002/ 此插件我用了下浏览器缓存有问题,而且当下拉框数据量过万后,会一直渲染不出来,期待后期作者优化 如图下 ...
- C++-HDU1000,1001,1002-格式是真的坑
#include <cstdio> int main(){ for(int a,b;~scanf("%d%d",&a,&b);printf(" ...
- 【译】用 `Wasmer` 进行插件开发 1
[译]用 Wasmer 进行插件开发 1 Using Wasmer for Plugins Part 1 译文 原文链接 https://wiredforge.com/blog/wasmer-plug ...
- 2.(group by)如何让分组后,每组中的数据按时间倒序排列(group by和 order by的分组按排列)
比如说有表devicedata: 问题: 现在我想将devicedata这个表中的数据,先按device_id这个字段分组,然后每组中的数据按时间字段ts从大到小的排列, 如何解决呢? 错误的sql: ...
- mp
问题 G: Green Bin 时间限制: 1 Sec 内存限制: 128 MB[提交] [状态] 题目描述 We will call a string obtained by arranging ...
- nginx的学习
什么是反向代理? 参考这个帖子的‘刘志军’的回答 https://www.zhihu.com/question/24723688 nginx的配置 http://baijiahao.baidu.com ...
- Java:不得不知的Object类
目录 一.equals 1.equals与==有啥区别? 2.equals方法的规范 3.instanceof 和getClass() 4.其他总结 二.hashCode 1.hashCode的规范 ...
- opencv:图像噪声
常见噪声的类型: 椒盐噪声 高斯噪声 其他噪声...... 手动生成图像噪声: #include <opencv2/opencv.hpp> #include <iostream> ...
- 【代码审计】seacms 前台Getshell分析
一.漏洞分析 漏洞触发点search.php 211-213行 跟进parseIf 函数 ./include/main.class.php 这里要注意 3118行的位置,可以看到未做任何处理的eval ...