可能重复:
选中特定单选按钮的检查
我现在有这两个单选按钮,以便用户可以决定是否需要包含在价格中的邮资:
<input type="radio" id="postageyes" name="postage" value="Yes" /> Yes
<input type="radio" id="postageno" name="postage" value="No" /> No
Run Code Online (Sandbox Code Playgroud)
我需要使用Jquery来检查是否选中了'yes'单选按钮,如果是,则执行追加功能.有人可以告诉我,我该怎么做?
谢谢你的帮助
编辑:
我已将我的代码更新为此,但它无效.难道我做错了什么?
<script type='text/javascript'>
// <![CDATA[
jQuery(document).ready(function(){
$('input:radio[name="postage"]').change(function(){
if($(this).val() == 'Yes'){
alert("test");
}
});
});
// ]]>
</script>
Run Code Online (Sandbox Code Playgroud) 我想查看所选的无线电输入是什么.
这是我的代码.
<input name="u_type" type="radio" value="staff" id="u_type" checked="checked" /> Staff
<input name="u_type" type="radio" value="admin" id="u_type" /> Admin
<input id="add_user" name="add_user" type="button" onclick="addUser();" value="Add" class="submitButton admin_add" />
function addUser()
{
//how to check what is the selected radio input
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我找到了执行此操作的脚本,但它们仅使用一个单选按钮名称,我有5个不同的单选按钮集.我怎样才能检查它现在是否被选中我在表单提交上试了一下
if(document.getElementById('radiogroup1').value=="") {
alert("Please select option one");
document.getElementById('radiogroup1').focus();
return false;
}
Run Code Online (Sandbox Code Playgroud)
不起作用.
我需要从所有选中复选框的 HTML 表中获取选中值
$('#table').input[checkbox].checked.getall();
Run Code Online (Sandbox Code Playgroud)
我需要这样的东西???
我已经搜索了很长一段时间,但我仍然不是明智的.我正在尝试为一个根据材料类型计算价格的网站做一个简单的计算器.我似乎无法让它工作.它一直踩到下面的switch语句的默认情况.
<div class="form-group">
<div class="btn-group" data-toggle="buttons" class="col-lg-3 col-lg-offset-10">
<label class="btn btn-default **active**">
<input type="radio" name="inputWalls" id="inputWalls" value="block" checked>Block</label>
<label class="btn btn-default">
<input type="radio" name="inputWalls" id="inputWalls" value="brick">Brick </label>
<label class="btn btn-default">
<input type="radio" name="inputWalls" id="inputWalls" value="stone">Stone </label>
Run Code Online (Sandbox Code Playgroud)
JAVASCRIPT
function quote(){
var blockPrice = 0;
var brickPrice = 0;
var stonePrice = 0;
var myWidth = parseFloat(document.getElementById("widthInput").value);
var myHeight = parseFloat(document.getElementById("heightInput").value);
var radioButtons = document.getElementsByName("inputWalls");
var totalArea = myWidth + myHeight;
switch(radioButtons){
case "block" :
blockPrice = totalArea * 1.90;
alert(blockPrice);
break; …Run Code Online (Sandbox Code Playgroud) 我想知道是否有人可以帮助我,我被困在需要编写像这样的小代码的地方。
Question : did you like the training?
<input type="radio" name="q4" value="Yes">Yes
<input type="radio" name="q4" value="No">No
Run Code Online (Sandbox Code Playgroud)
无论检查什么,我都想将它传递给一个 javascript 变量。