手写CSS+js实现radio单选按钮

Posted 额爷

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手写CSS+js实现radio单选按钮相关的知识,希望对你有一定的参考价值。

有的时候我们需要用长得漂亮一点的单选按钮,那么,就要抛弃原有的自己来写,下面就是我实现的

<div class="radio"><span class="yuan rdactive"><span></span></span>你丑你先</div>
	<div class="radio"><span class="yuan"><span></span></span>你才丑你先</div>
<div class="radio"><span class="yuan"><span></span></span>你更丑你先</div>
	.radio{
		display: flex;
		align-items: center;
		width: 100px;
		cursor: pointer;
	}
	.yuan{/*大圈*/
		display: block;
		width: 10px;
		height: 10px;
		border-radius: 50%;
		background: #ececec;/*这里写自己喜欢的颜色*/
		display: flex;
		align-items: center;
		margin-right: 5px;
	}
	.radio>span.rdactive{
		background: #EF6121;/*这里写自己喜欢的颜色*/
	}
	.yuan span{/*小圈*/
		display: block;
		width: 4px;
		height: 4px;
		border-radius: 50%;
		background: white;/*这里写自己喜欢的颜色*/
		margin: 0 auto;
	} 
$(".radio").children(\'.yuan\').on(\'click\',function(){
	$(\'.rdactive\').removeClass(\'rdactive\');
	$(this).addClass("rdactive").siblings().removeClass("rdactive");
})

  效果图:

好啦,到这里就可以实现啦

以上是关于手写CSS+js实现radio单选按钮的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript 单选按钮检查相关问题

验证码的设计与记住我存储用户名密码cookie的技术及单选按钮选择登录人身份的实现

js+css--单选按钮,自定义选中的颜色???(性别按钮,男女)

无敌秘籍之 — JavaScript手写代码

css实现iPhone的切换按钮

如何使用js获取选定的单选按钮值