如何创建单选框文本库
How to create radiobox text base
嘿,我知道如何创建一个基于图像的单选
框,问题是如何创建一个只有文本的单选框(单选按钮被隐藏)? 并且文本是可点击的。
我从您的问题中了解到您想要一个文本单选按钮,即文本可单击并传递值 (0,1),而不是圆圈,因此请检查此代码希望对您有所帮助....
<head>
<title>Test</title>
<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>
<style>
label{
border:1px blue solid;
padding:10px;
margin:20px;
}
</style>
<script>
$("document").ready(function(){
//alert('ok');
var tr;
$("#txtradio").click(function(){
//alert('ok');
tr = tr==0?1:0;
//alert(tr);
if(tr==1){
$("label").css({"background-color":"blue","color":"white"});
}else{
$("label").css({"background-color":"white","color":"black"});
}
});
})
</script>
</head>
<body>
<label id="txtradio">
sunil
</label>
</body>
你可以尝试这样的事情:
<!DOCTYPE html>
<html>
<head> <style type="text/css">
input[type='radio'] {
opacity:0;
}
</style>
</head>
<body>
<label for="male">Male</label>
<input type="radio" name="gender" id="male" value="male"><br>
<label for="female">Female</label>
<input type="radio" name="gender" id="female" value="female"><br>
<label for="other">Other</label>
<input type="radio" name="gender" id="other" value="other"><br><br>
</body>
</html>
HTML:
<input type="radio" id="radio1" name="radio_name" value="1" checked="checked">
<label for="radio1">Radio 1</label>
<br />
<input type="radio" id="radio2" name="radio_name" value="2">
<label for="radio2">Radio 2</label>
<br />
<input type="radio" id="radio3" name="radio_name" value="3">
<label for="radio3">Radio 3</label>
.CSS:
input[type="radio"] { display:none; }
input[type="radio"]:checked + label{ font-weight: bold }
此处的简单演示:JSFiddle
答案很简单
input[type="checkbox"] {
position:absolute;
opacity:0;
}
input[type="checkbox"] + span {
border:2px solid #D3D3D3;
border-radius:6px;
}
input[type="checkbox"]:checked + span {
border-color:#4df;
}
<label>
<input class="graph_checkbox" type="checkbox" /><span>HelloWorld</span>
</label>
相关文章:
- 选中单选框时将属性添加到输入字段
- 选中单选框时禁用输入框
- 基于单选框更新页眉,选中并选择输入文本
- 选中单选框时,将文本添加到文本框中
- 如果选中单选框,则将值添加到合计
- 使用javascript提交表单并从字段/单选框/复选框/文本区域获取数据
- html/jquery输入类型:单选框中的文本不起作用
- 按字母顺序对输入单选框进行排序
- 使用JQuery启用输入字段的单选框
- 如果所有单选框在jQuery中都有一个选择,则显示一个元素
- 如何在应用jquery buttonset()后取消选中所有具有相同类名的单选框
- 默认情况下无法预先选择所需的单选框
- 当选择特定的单选框时,使用jquery禁用循环中的文本框
- 如何使用选中的复选框文本自动填充输入文本字段
- Angular,获取Ng中复选框(或单选框)所需的Ng重复
- 如何创建单选框文本库
- 验证是否选中了分组单选框
- Jquery 单选框选中查找显示以前选中的项目
- 选中单选框输入时切换文本输入
- 禁用基于其他单选框选择的文本框