【问题标题】:Grails radio button show hidden div with onclickGrails单选按钮通过onclick显示隐藏的div
【发布时间】:2015-12-08 17:31:46
【问题描述】:

我的 _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>

我隐藏的 div 是

<div id="locationTable" style="display: none">
  <table style="width: 100%;">
    <tr>
      <td>HERES LOCATION INFORMATION</td>
    </tr>
  </table>
</div>

我的 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>

日期选择器有效,但显示位置信息功能无效。我做错了什么?

【问题讨论】:

    标签: javascript jquery html grails


    【解决方案1】:

    在您的showLocInfo 中,elem.checked 是布尔值,而不是字符串。由于您使用的是 2 个 if 语句,而不是 if/else,因此不会执行任何块,从而导致没有任何行为。

    尝试改用:

    if (elem.checked === true) { 
        // ..
    

    【讨论】:

      猜你喜欢
      • 2011-03-05
      • 1970-01-01
      • 2019-01-20
      • 2015-01-28
      • 1970-01-01
      • 2013-12-30
      • 2013-06-25
      • 1970-01-01
      • 2013-07-06
      相关资源
      最近更新 更多