是否可以创建像 JQuery 这样的单选按钮那些,纯 html/css?
谢谢
最佳答案
试试这个 fiddle :http://jsfiddle.net/mcXm7/1/
这个例子是 100% 纯 CSS,它在较新的浏览器上运行良好(当然可以随意添加所有必要的样式以使按钮看起来像您的示例)
HTML
<input type="radio" name="rd" id="choice1" value="1">
<label for="choice1" >Choice 1</label>
<input type="radio" name="rd" id="choice2" value="2">
<label for="choice2" >Choice 2</label>
<input type="radio" name="rd" id="choice3" value="3">
<label for="choice3" >Choice 3</label>
CSS
label { display : inline-block;
padding : 2px 5px;
cursor : pointer;
border : 1px #b6b6b6 outset; }
input[type="radio"] {
display: none;
}
input[type="radio"]:checked + label {
border: 1px #b6b6b6 inset;
}
/* hover style */
input[type="radio"] + label:hover { ... }
input[type="radio"]:checked + label:hover { ... }
不幸的是:checked
IE<9
不支持:见http://www.impressivewebs.com/css3-support-ie9/对于可用的 css/css3 功能的完整列表,因此对于较旧的浏览器,需要 javascript 回退才能正常工作。
JS 回退的基本示例:http://jsfiddle.net/mcXm7/2/ (不需要同时加载 jQuery UI)
关于jquery - 带有纯 html/css 的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9513272/