【前端】input radio多选事件获取所有选中的id,radio样式优化可修改

$("#all_button").on(‘click‘, function() {
obj = document.getElementsByClassName("input_radio_checked");
str = "";
for(i = 0; i < obj.length; i++) {
str += obj[i].id + " "; //这里是数字之间的空格
}
console.log(str)
alert(str)
})

radio样式优化css

<!--新增选择-->
<div class="fl radio"><input id="2" class="input_radio" type="radio" name="2" value=""><label for="2"></label></div>
<!---->

css如下:

.radio{
position: relative;
line-height: 30px;
margin-top: 1.4rem;
margin-left: 0.6rem;
}
 .radio{
position: relative;
line-height: 30px;
margin-top: 1.4rem;
margin-left: 0.6rem;
}

input[type="radio"] {
width: 20px;
height: 20px;
opacity: 0;
}

label {
position: absolute;
left: 5px;
top: 3px;
width: 20px;
height: 20px;
border-radius: 50%;
border: 1px solid #999;
}

/*设置选中的input的样式*/
/* + 是兄弟选择器,获取选中后的label元素*/
.top_color {
background-color: #fe6d32;
border: 1px solid #fe6d32;
}

.top_color::after {
position: absolute;
content: "";
width: 5px;
height: 10px;
top: 3px;
left: 6px;
border: 2px solid #fff;
border-top: none;
border-left: none;
transform: rotate(45deg)
}

效果:

原文地址:https://www.cnblogs.com/xiaohuizhang/p/8624011.html

时间: 2024-08-26 23:36:48

【前端】input radio多选事件获取所有选中的id,radio样式优化可修改的相关文章

JQuery 判断checkbox是否选中,checkbox全选,获取checkbox选中值

<!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> <meta http-equiv="Content-

jq获取被选中的option的值。jq获取被选中的单选按钮radio的值。

温故而知新,一起复习下jq的知识点. (1) jq获取被选中的option的值 <select id="select_id"> <option value="0">请选择</option> <option value="1">11111111111</option> <option value="2>222222222</option> <opti

input file多选时获取的文件字节与文件不对应的问题

window.onload = function(){ var input=document.getElementById("file"); if ( typeof(FileReader) === 'undefined' ){ input.setAttribute( 'disabled','disabled' ); } else { input.addEventListener( 'change',xmTanUploadImg,false );} } //选择图片,马上预览 funct

checkbox的选中、全选、返选、获取所有选中的值、所有的值、单选全部时父选中

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><h

jquery单选框radio绑定click事件实现和是否选中的方法

使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: 1.<input type="radio" name="testradio" value="jquery获取radio的值" />jquery获取radio的值2.<input type="radio" name=&

动态获取input内容文本 - js事件

要想通过事件实时获取文本框文本,一开始是想到下面的方法,但实际效果都存在一定的缺点. 通过change/blur事件获取 change事件只有在选中点击或者失焦的时候,才能够触发. blur事件则是只能在失焦才能除法. 我最初选择的是change事件,而这样显然是不符合实时获取的要求的. 然后在查找文档的时候,发现了input事件,这里的input指的是事件的名字.mdn对于input事件的解释是: 每当<input>元素的value值改变时,都会触发这个事件. 这个显然很适合我们的需求,先写

jquery修改获取radio的选中项

<input id="txtBeginDate" onclick="$('#divDate').css({'top':$('#txtBeginDate').offset().top+'px','left':$('#txtBeginDate').offset().left+'px'})" style="width:170px;padding:7px 10px;border:1px solid #ccc;margin-right:10px;"/

以input=file方式,获取文件时,在IE下8无法通过某个按钮click事件间接触发input=file的change事件

最近在项目中遇到了许多上传问题,公司内部的组件,通过form上传,需要使用input=file触发选择文件, 因为input=file在各个浏览器中显示的样式是不同的,谷歌,火狐,IE都有所不同,而且不太美观,所以为了解决 这一个问题,一开始采用了隐藏input=file 然后通过一个显示的button间接触发input=file的click事件如下 <input type="file" id="upload" style="display:none

使用jquery获取被选中checkbox复选框的值

使用jquery获取被选中checkbox复选框的值:checkbox是重要的表单元素,在很多多项选择中使用,下面就通过代码实例介绍一下如何获取复选框中所有被选中项的值,希望能够给需要的朋友带来一定的帮助.代码如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.