或者如果你想自己做...
我会做的是与<button>
元素和隐藏的表单字段元素记住哪一个是“按下”像这样创建的按钮:
<button type="button" id="btn1">Choice 1</button>
<button type="button" id="btn2">Choice 2</button>
<button type="button" id="btn3">Choice 3</button>
<input type="hidden" id="btnValue" value="" />
您将CSS来表明按钮被“按下”或不“按下”所以你会需要它们在默认情况下是这样的:
button
{
border-width: 2px;
border-style: outset;
border-color: /*Insert a darker version of your button color here*/
}
然后在jQuery的(如果你能在jQuery的做到这一点,你可以做到这一点的直JavaScript,所以请记住,如果你d on't想使用jQuery):
$("#btn1").click(function() {
$(this).css("border-style", "inset")
$("#btn2").css("border-style", "outset;");
$("#btn3").css("border-style", "outset;");
$("btnValue").val("btn1IsPressed");
});
$("#btn2").click(function() {
$(this).css("border-style", "inset")
$("#btn1").css("border-style", "outset;");
$("#btn3").css("border-style", "outset;");
$("btnValue").val("btn2IsPressed");
});
$("#btn3").click(function() {
$(this).css("border-style", "inset")
$("#btn1").css("border-style", "outset;");
$("#btn2").css("border-style", "outset;");
$("btnValue").val("btn3IsPressed");
});
现在,所有你需要做的就是请求#btnValue
POST后的值(或GET或其他),就像你通常会告诉他们有哪些“按钮”按下。
请注意,您需要添加一些功能来“解除”按钮,但我认为您明白了。您只需在点击时读取#btnValue
的值,并与其他语句一起使用if分支来处理它是否已被按下,并相应地切换边界(不要忘记清除(""
)值为#btnValue
的“解压”按钮,以便您可以判断他们是否将它们全部未按下)。
您是否尝试过在SO上搜索“自定义单选按钮”? [例如。 http://stackoverflow.com/questions/9266868/custom-radio-buttons-ie-will-kill-me] – Orbling 2013-04-26 18:33:16
试试这个http://jqueryui.com/button/#radio,这可能ñ你在找什么。 – PSL 2013-04-26 18:36:12
用户对按钮有一定的期望,您确定这是明智的做法吗? – cimmanon 2013-04-26 18:53:20