【发布时间】:2011-11-18 10:34:42
【问题描述】:
我有两组按钮,我喜欢让按钮像单选按钮一样,所以只能选择一个。
例如:
<div id="top">
<div class="span2">
<input type=button value="10" id="top_A" name="top_A" onclick="yourPick(this)"/>
</div>
<div class="span2">
<input type=button value="20" id="top_B" name="top_B" onclick="yourPick(this)"/>
</div>
</div>
<div id="bottom">
<div class="span2">
<input type=button value="30" id="top_C" name="top_C" onclick="yourPick(this)"/>
</div>
<div class="span2">
<input type=button value="40" id="top_D" name="top_D" onclick="yourPick(this)"/>
</div>
</div>
因此您可以在顶部选择按钮 10 或 20,而在 div 底部选择按钮 30 或 40。
有什么建议吗?
ps:
function yourpick(pick){
var pValue= pick.value;
alert(pValue);
$('#topPick').val(pValue);
$('#bottomPick').val(pValue);
}
【问题讨论】:
-
jquery ui 中的jqueryui.com/demos/button/#radio 怎么样?
-
单选按钮有什么问题?
-
@charpsi ,目前界面是基于按钮的。所以对于用户来说,我喜欢一直使用按钮。马特看起来很有希望我会检查一下
-
@matt 我正确地假设您的链接使用单选按钮,通过在开始 - 结束标记之间添加标签来看起来像按钮??
-
@alex,是的,它们就像单选按钮一样,但它们的样式是按钮。您可以只使用 jquery 主题滚轮来随意设置它的样式。然后使用您添加标签,介于两者之间的将是显示的文本。因此,如果有人没有启用 javascript,这是有效的 HTML 和兼容的。