首页 > 解决方案 > 如何使用 JQuery 动态显示 div 标签?

问题描述

我的代码有什么问题?它没有显示我的期望。这就是我的代码的样子:

$(document).ready(function(){

  ...
  $('input[name=hdr_approval]').change(function(){
    if($('input:radio[name=hdr_approval]')[0].checked == true){
      $('#stage-action').css('display', 'block');
    }else{
      $('#stage-action').css('display', 'none');
    }
  });

  if($('input[name=hdr_approval]:checked').length > 0 || $('#stage').val() === 'Personal Qualification Data'){
    $('#stage-action').css('display', 'block');
    console.log(document.getElementById("stage").value);
  }else{
    $('#stage-action').css('display', 'none');
  }

  console.log(document.getElementById("stage-action").style.display);
  ...
});

这是我的页面的一部分:

<div class="col s6 m6 l6 body-reset">
    <div class="right-align col s11 body-reset" style="height: inherit !important;">
        <p id="stage-text" class="custom-stage-text" style="height: inherit !important; top: 0px !important; padding-top: 0px; margin-top: 0px; ">
            @switch($application->stage)
            @case('Credential Review')
            {{ 'Personal Qualification Data' }}
            @break
            @case('Personal Qualification Data')
            {{ 'Proceed to Qualifying Exam' }}
            @break
            @endswitch
        </p>
    </div>
    <div class="right-align col s1">
        <button type="submit" id="stage-action" name="action_submit" form="lt-edit-form" class="btn-flats box"><i class="fas fa-chevron-circle-right"></i></button>
    </div>
</div>

默认情况下,我的stage-action显示设置为无。

我的日志正在输出应该做的事情,但我不知道为什么stage-action没有显示在我的页面上。

标签: javascriptjquery

解决方案


推荐阅读