我有一个应用程序,当选择某个单选按钮时显示一个div,然后在取消选择单选按钮时隐藏该div.问题是附加到单选按钮的更改事件仅在选中单选按钮时被调用,而不是在选中另一个单元时被调用(取消选中前一个).我目前的代码如下:
<form name="newreport" action="#buildurl('report.filters')#" method="post">
<dl class="oneColumn">
<dt class="first"><label for="txt_name">Name</label></dt>
<dd><input type="text" name="name" id="txt_name" class="text" /></dd>
<dt><strong>Type</strong></dt>
<dt><input type="radio" name="type" id="rdo_list" value="list" checked="checked" /><label for="rdo_type" style="display:inline;">List</label></dt>
<dd>List a group of records</dd>
<dt><input type="radio" name="type" id="rdo_fields" value="fields" /><label for="rdo_fields" style="display:inline;">Field Breakdown</label></dt>
<dd>Breaks down distinct field values for comparison</dd>
<dt><input type="radio" name="type" id="rdo_history" value="history" /><label for="rdo_history" style="display:inline;">Historical Comparison</label></dt>
<dd>Provides record changes over a group of years for growth comparisons</dd>
<dt><input type="radio" name="type" id="rdo_breakdown" value="breakdown" /><label for="rdo_breakdown" style="display:inline;">Student Breakdown</label></dt>
<dd>Breaks down students by …Run Code Online (Sandbox Code Playgroud) 看完jQuery文档后我遇到了麻烦.我只是试图在我的jquery方法中返回true/false,具体取决于对某个radiobutton的检查以及是否选中
我已经尝试了几件事,但未能做到这一点:
<input type="radio" runat="server" name="testGroup" id="test1" /><label for="<%=test1.ClientID %>" style="cursor:hand" runat="server">Test1</label>
<input type="radio" runat="server" name="testGroup" id="test2" /><label for="<%=test2.ClientID %>" style="cursor:hand" runat="server">Test2</label>
<input type="radio" runat="server" name="testGroup" id="test3" /> <label for="<%=test3.ClientID %>" style="cursor:hand">Test3</label>
Run Code Online (Sandbox Code Playgroud)
在我的方法中我有这个:
return $("input[@name='test2']:checked");
Run Code Online (Sandbox Code Playgroud)
我得到一个未定义的 $("input[@name='test2']:checked");
更新:
例:
<input type="radio" runat="server" name="radioGroup" id="payPalRadioButton" value="paypalSelected" />
Run Code Online (Sandbox Code Playgroud)
这仍然会返回'undefined':
$("input[@name=radioGroup]:checked").attr('payPalRadioButton');
Run Code Online (Sandbox Code Playgroud)
如果我试试这个,即使我选择了单选按钮,我也会"假":
$('input:radio[name=radioGroup]:checked').val() == 'paypalSelected'
Run Code Online (Sandbox Code Playgroud) 嗨伙计们我有问题.
我正在从数据库中检索一些值,并将其显示在一个表单中进行编辑.编辑完成后,值将发送回DB.
如果选中值为"是"的收音机,我想显示一个div,如果选中值为"No"的收音机,我想显示另一个div.
检查的值来自数据库,因此它并不总是在同一台无线电上.
<input type="radio" name="longer" id="Yes" value="Yes" <?=($info['longer']=='Yes')?'checked':''?>>Yes
<input type="radio" name="longer" id="No" value="No" <?=($info['longer']=='No')?'checked':''?>>No
<div id="first">
Show if value is yes
</div>
<div id="second">
Show if value is no
</div>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的jquery代码,但它不起作用:
$(document).ready(function() {
if ($('#No').prop('checked')) {
$('#first').hide();
$('#second').show();
} else if ($('#Yes').prop('checked') {
$('#second').hide();
$('#first').show();
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间.
我正在使用jQuery .val()从包含两组单选按钮的表单中提取数据结果.
<!DOCTYPE HTML>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function userPrefsSubmitted() {
console.log( $('form input[@name=cssOn]:checked').val() );
console.log( $('form input[@name=halfFramesOn]:checked').val() );
}
</script>
</head>
<body>
<p>Choose User Prefs</p>
<form>
<p>Transitions</p>
<div><input type="radio" name="cssOn" value=true>True</div>
<div><input type="radio" name="cssOn" value=false>False</div>
<p>Half Frames</p>
<div><input type="radio" name="halfFramesOn" value=true>True</div>
<div><input type="radio" name="halfFramesOn" value=false>False</div>
<br/><br/>
<input class="submitButton" type="button" onClick="userPrefsSubmitted()" value="tap when done" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我选择fasle然后是true并按下按钮,则console.log显示false false
这让我疯狂,我搜索这个论坛以及互联网,但没有找到答案.我哪里错了?