radio,checkbox,select,input text获取值,设置哪个默认选中
11
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试表单获取元素值</title>
<link rel="stylesheet" type="text/css" href="../bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script>
<style type="text/css">
*{
margin: ;
padding: ;
}
.main{
padding: 0px 15px;
}
input{
margin-right: 15px;
display: inline-block;
}
</style>
</head>
<body>
<div class="main">
<div class="row">
<label>姓名:</label><input type="text" name="name" value="" />
</div>
<div class="row">
<label>多选:</label>
<label for="checkbox1">多选1:</label><input type="checkbox" name="多选" id="checkbox1" value="checkbox1">
<label for="checkbox2">多选2:</label><input type="checkbox" name="多选" id="checkbox2" value="checkbox2">
<label for="checkbox3">多选3:</label><input type="checkbox" name="多选" id="checkbox3" value="checkbox3">
</div>
<div class="row">
<label>下拉:</label>
<select name="opt">
<option value="opt1" name="opt">下拉1</option>
<option value="opt2" name="opt">下拉2</option>
<option value="opt3" name="opt">下拉3</option>
<option value="opt4" name="opt">下拉4</option>
</select>
</div>
<div class="row">
<label>单选:</label>
<label for="radio1">单选1:</label><input type="radio" name="radio" id="radio1" value="radio1">
<label for="radio2">单选2:</label><input type="radio" name="radio" id="radio2" value="radio2">
<label for="radio3">单选3:</label><input type="radio" name="radio" id="radio3" value="radio3">
<label for="radio4">单选4:</label><input type="radio" name="radio" id="radio4" value="radio4">
</div>
<button id="submit">提交</button>
</div>
<script type="text/javascript">
$("#submit").on("click",function(){
//给多选框的某个选中
$(".main").find("input[name='多选']")[].checked=true;
//获取多选框选中的索引:
console.log("多选框suoyin:"+$("input[name='多选']").index($("input[name='多选']:checked")));
//获取复选框选中的值:
var arr=document.getElementsByName("多选");
for(var i=;i<arr.length;i++){
if(arr[i].checked){
console.info("多选框:"+arr[i].value);
}
}
//反选
// $('input[name="多选"]').each(function () {
// $(this).prop("checked", !$(this).prop("checked"));
// }); //输入框设置值
$("input[name='name']").val("wlz111")
//获取输入框值:
console.info("输入框:"+$("input[name='name']").val()); //将下拉框设置成某个值
$(".main").find("select[name='opt']").get().selectedIndex = ;
//获取下拉框值
console.log("下拉框:"+$('select').val()); //单选按钮设置值
$(".main").find("input[name='radio']")[].checked=true;
//获取单选按钮的值:
console.log("单选按钮:"+$(".main").find("input[name='radio']:checked").val());
//获取单选按钮选中的索引:
console.log("单选按钮suoyin:"+$("input[type=radio]").index($("input[type=radio]:checked"))); })
</script>
</body>
</html>
radio,checkbox,select,input text获取值,设置哪个默认选中的更多相关文章
- jSP的3种方式实现radio ,checkBox,select的默认选择值。
jSP的3种方式实现radio ,checkBox,select的默认选择值.以radiao 为例:第一种方式:在jsp中使用java 脚本,这个方法最直接,不过脚本太多,不容易维护<%Stri ...
- 【TP3.2+onethink】radio+checkbox+select 空间 编辑页面选中,附录 js 返回上一页
1.TP3.2框架 如何实现 [radio+checkbox+select 空间 编辑页面选中],说实话,比较繁琐,不咋地!! 不废话,上代码:(其中 XX_arr 变量一维数组) <div ...
- Jquery获取input=text 的值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Jquery操作radio,checkbox,select表单操作实现代码
一 .Select jQuery获取Select选择的Text和Value: 1. $("#select_id").change(function(){//code...}); / ...
- Radio Checkbox Select 操作
一个小总结 <!DOCTYPE html> <html> <head> <meta name="description" content= ...
- 今个忽然晓得,原来radio不是普通去获取值的!
今日,写js校验.对于不太会的,总是陌生的.碰见radio的取值,习惯的用document.getElementsByName("")[0].value去获取值,却忘记了radio ...
- 【VC++技术杂谈002】打印技术之获取及设置系统默认打印机
本文主要介绍如何获取以及设置系统的默认打印机. 1.获取系统中的所有打印机 获取系统中的所有打印机可以使用EnumPrinters()函数,该函数可以枚举全部的本地.网络打印机信息.其函数原型为: B ...
- 用jQuery的attr()设置option默认选中无效的解决 attr设置属性失效
表单下拉选项使用selected设置,发现第一次默认选中成功,在页面不刷新的情况下,再次下拉,selected属性设置了,默认选中不生效 在手机端有些浏览器用jQuery的attr()方法设置sele ...
- RadioButtonFor值为false.默认选中的问题
(自己看了下.图片有点宽.显示的不全.可以右键新标签查看) 作为一个新手.今天又开始了mvc的学习之旅.然而学习过程中又遇到了一个奇妙的问题.... 一切按部就班到了这里.注册界面. 一眼看上去就不对 ...
随机推荐
- 【openwrt+arduion】案例
http://www.geek-workshop.com/thread-4950-1-1.html http://www.guokr.com/article/319356/ http://www.gu ...
- ASP.NET MVC:Expression Trees 作为参数简化查询
ASP.NET MVC 引入了 ModelBinder 技术,让我们可以在 Action 中以强类型参数的形式接收 Request 中的数据,极大的方便了我们的编程,提高了生产力.在查询 Action ...
- C++ 智能指针学习
C++ Code 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...
- Linux环境下Apache配置多个虚拟主机挂载多站点同时运行
博客地址: http://blog.csdn.net/ClydeKuo/article/details/69569474 这篇博客讲的很详细,很详细.
- 使用 awk 过滤文本或文件中的字符串
当我们在 Unix/Linux 下使用特定的命令从字符串或文件中读取或编辑文本时,我们经常需要过滤输出以得到感兴趣的部分.这时正则表达式就派上用场了. 什么是正则表达式? 正则表达式可以定义为代表若干 ...
- 折腾deeplin系统
1.双系统失败记录 多系统启动问题 先安装完deepin,发现再安装windows怎么都起不起来,哪怕他们已经安装在不同的盘 (体现再Windows7通过ghost位于另外一个盘,但就是没有启动项) ...
- 76、android:supportsRtl 和 android:layout_marginEnd
android4.2(SDK版本为17)有一个新特性 layoutRtl,当然是对于开发者而言的,主要是方便开发者去支持阿拉伯语/波斯语等阅读习惯是从右往左的. 可以在manifest的applica ...
- 应急分析异常通信的小思路和自己写的小工具(查询CNAME和A记录)
一.背景: 在很多时候,应急会发现.卧槽,异常连接,只有一个域名或者IP. 怎么办?上防火墙看记录,查域名对应的记录累成狗,自己把之前的代码改了改,写了个小工具,一条命令查询DNS相关记录,也可以指定 ...
- 基于开源博客系统(jpress)搭建网站
基于开源博客系统(jpress)搭建网站 JPress 使用 Java8 开发,基于流行的JFinal和Jboot框架. 目前JPress已经内置的文章和页面其实是两个模块,可以移除和新增其他模块,因 ...
- quartz启动Quartz : org.quartz.SchedulerConfigException: Thread count must be > 0
检查quartz.properties数据源配置是否正常