[英]Grails radio button show hidden div with onclick
My radio button in my _form.gsp is coded as 我的_form.gsp中的单选按钮编码为
<table>
<thead>
...
</thead>
<tbody>
<g:each in="${locationList}" status="i" var="location">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
...
<td><g:radio name="location" value="${location.id}" onclick="showLocInfo(this)" checked="${false}" /></td>
</tr>
</g:each>
</tbody>
</table>
and my hidden div is 我隐藏的div是
<div id="locationTable" style="display: none">
<table style="width: 100%;">
<tr>
<td>HERES LOCATION INFORMATION</td>
</tr>
</table>
</div>
My create.gsp contains some javascript in the head which currently isn't working 我的create.gsp头部包含一些JavaScript,目前无法正常运行
<head>
...
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript">
$(function() {
$(".datepicker").datepicker();
});
jQuery.noConflict();
function showLocInfo(elem){
if (elem.checked == "true") {
document.getElementById('locationTable').style.display = "block";
}
if (elem.checked == "false") {
document.getElementById('locationTable').style.display = "none";
}
}
</script>
</head>
The datepicker works, but the show location info function does not. 日期选择器有效,但显示位置信息功能无效。 What am I doing wrong?
我究竟做错了什么?
In your showLocInfo
, elem.checked
is a boolean, not a string. 在
showLocInfo
, elem.checked
是布尔值,而不是字符串。 Since you are using 2 if
statements, rather than an if/else
, neither block is executed, resulting in no behavior. 由于您使用的是2条
if
语句,而不是if/else
,因此不会执行任何块,因此不会产生任何行为。
Try using instead: 尝试改用:
if (elem.checked === true) {
// ..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.