HTML使常规按钮的行为类似于一组单选按钮 [英] HTML make regular buttons act like a group of radio buttons
本文介绍了HTML使常规按钮的行为类似于一组单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望得到一些常规按钮,就像一组单选按钮一样。
I want to get some "regular" buttons to act like a group of radio buttons.
我发现了一个jQueryUI插件,可以完全符合我的要求: http://jqueryui.com/demos/button/#radio
I found a jQueryUI plugin that does exactly what I want: http://jqueryui.com/demos/button/#radio
但是我想避免在我的项目中添加另一个库。知道如何使用纯HTML + javascript / jQuery完成这项工作吗?
But I'd like to avoid adding another library to my project. Any idea how this could be done using pure HTML + javascript/jQuery ?
提前致谢
推荐答案
演示: http://jsfiddle.net/CXrgm/6
$('.button').click(function() {
$('.button').removeClass('active');
$(this).addClass('active');
});
其中 .button
是你的标记类您需要包含的所有按钮,以及 .active
类whitch表示所选按钮。
where .button
is your marker class for all buttons you need to include, and .active
class whitch is indicate selected button.
以获取所选按钮使用:
$('.button.active') // get attribute value, etc. Whatever you need.
这篇关于HTML使常规按钮的行为类似于一组单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文