使用Twitter Bootstrap切换单选按钮,获取表单输入的简洁方法是什么? [英] With Twitter Bootstrap toggle radio buttons, what's the clean way to get form input?

查看:93
本文介绍了使用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.

它运作良好,但它仍然是一种kludge。我的问题是:从这些按钮获取表单输入的简洁方法是什么,即没有额外的隐藏无线电输入?

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()

DEMO

我想我第一次误读了你的问题......你可以创建一个隐藏的表单元素(你需要它)在提交表单时访问该值,除非你使用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'));

})​

DEMO

这篇关于使用Twitter Bootstrap切换单选按钮,获取表单输入的简洁方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆