我有表格 用户必须在按钮之间进行选择 我制作了html代码,并制作了jquery代码,使该选项处于活动状态(已选中) 但我不知道如何选择进入php(如何知道用户选择的内容) 我的想法是创建一个javascript函数,用所选选项
创建隐藏输入HTML:
<div class="btn-group" role="group" style="padding:20px;">
<button type="button" class="btn btn-primary active">Manual</button>
<button type="button" class="btn btn-primary">Automatic</button>
<button type="button" class="btn btn-primary">Both</button>
</div>
使用Javascript:
<script>
$('.btn-group').on('click', '.btn', function() {
$(this).addClass('active').siblings().removeClass('active').addClass('btn-default');
});
</script>
答案 0 :(得分:0)
将表单控件包装在<form>
中,并确保包含值的每个表单控件都有name
。使用<input type='submit'>
或使用AJAX将数据发送到服务器。此演示使用测试服务器。选择一个单选按钮并单击提交按钮,您将收到服务器如何查看您发送的内容的数据和标题。由于SO的安全措施,Snippet无法正常运行,因此请转到此PLUNKER进行工作演示。
参考:http://www.dyn-web.com/tutorials/forms/
<强>段强>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form id='form1' name="form1">
<fieldset>
<legend>Choose Transmission</legend>
<label>Manual</label>
<input type='radio' name='rad' value='Manual'>
<label>Auto</label>
<input type='radio' name='rad' value='Auto'>
<label>Both</label>
<input type='radio' name='rad' value='Both'>
</fieldset>
<input id="submit" type="submit">
<br/>
<label>Result:
<!-- Output area. -->
<output id="output1"></output>
</label>
<div>This Snippet will not function in SO due to security contraints. Go here for a working demo: https://embed.plnkr.co/Yv6POGH9Jvbgs1HFoQrX/
</div>
</form>
<script>
var f1 = document.getElementById('form1');
var o1 = document.getElementById('output1');
f1.onsubmit = function(e) {
e.preventDefault();
var req = new XMLHttpRequest();
// POST to httpbin which returns the POST data as JSON
req.open('POST', 'http://httpbin.org/post', false);
var formData = new FormData(f1);
req.send(formData);
o1.value = req.response;
}
</script>
</body>
</html>
&#13;