使用 Twitter Bootstrap 切换单选按钮,获取表单输入的简洁方式是什么?

编程入门 行业动态 更新时间:2024-10-27 10:22:09
本文介绍了使用 Twitter Bootstrap 切换单选按钮,获取表单输入的简洁方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 Twitter Bootstrap 的 Javascript 单选切换按钮,并且想要获取表单基于切换状态的输入.

I am using Twitter Bootstrap's Javascript radio toggle buttons and want to get form input based on the state of the toggle.

我能找到的最简单的方法是在按钮中添加一个不可见的标签 -- 这里是有用的 jsFiddle 某人吐出的例子.

The simplest approach I could find is to add an invisible tag within the buttons -- here's the helpful jsFiddle example that someone threw up.

它工作得很好,但它仍然有点杂乱无章.我的问题是:从这些按钮获取表单输入的干净方式是什么,即没有额外的隐藏单选输入?

It works nicely, but it's still sort of a kludge. My question is: what's the clean way to get form input from these buttons, i.e. without the extra hidden radio inputs?

推荐答案

怎么样

$(this).children('input[name="is_private"]').val()

演示

我想我第一次看错了你的问题......你可以创建一个隐藏的表单元素(你需要它在提交表单时访问值,除非你做 AJAX)并使用 JS 来设置它的值.

I think I misread your question the first time... You can create a hidden form element (you need it to access the value when you submit the form unless you do AJAX) and use JS to set its value.

HTML

<input type="hidden" name="status" id="status" value="" />

JS

$('div.btn-group button').click(function(){ $("#status").attr('value', $(this).attr('id')); })​

演示

更多推荐

使用 Twitter Bootstrap 切换单选按钮,获取表单输入的简洁方式是什么?

本文发布于:2023-10-12 02:39:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   单选   简洁   按钮   方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!