即使条件为真也无法显示div,始终在php中显示else部分

时间:2019-04-17 11:52:02

标签: javascript php jquery yii2-advanced-app

仅在条件为真时,我才尝试在选项卡单击上显示div,但即使条件为真,我也总是在其他部分中显示else div

 $('#err').removeClass('uk-active'); 
 $('#MA_st').addClass('uk-active');

我已经在成功进行ajax调用时尝试了上述代码,还尝试了以下选项卡单击操作

 $("#tab_list").on('click','li',function (){
      $('#err').removeClass('uk-active'); 
      $('#MA_st').addClass('uk-active');
 });

这是我的php代码,用于在视图文件中显示div

<?php 
  $state_val = "";
  if(isset($_GET['state_val'])){
    $state_val = $_GET['state_val'];
    print_r($state_val);
  }
  if($data['state'] == 'MA' || $state_val == 'MA'){?>
    <div id="MA_st">
      <li>
          <div class="uk-form-row">
              <label class="uk-form-label"><?php echo Yii::t("default","Number")?></label>
              <?php echo CHtml::textField('txt_number',
                  isset($data['number'])?$data['number']:""
                  ,array(
                      'class'=>'uk-form-width-large'
                  ))?>
          </div>

          <div class="uk-form-row">
              <label class="uk-form-label"><?php echo Yii::t("default","Name")?></label>
              <?php echo CHtml::textField('txt_name',
                  isset($data['name'])?$data['name']:""
                  //"ABC"
                  ,array(
                      'class'=>'uk-form-width-large',
                      'autocomplete'=>"off"
                  ))?>
          </div>
      </li>
  </div>
<?php }else{?>
    <div id="err">
    <p>Inforamtion is not avaialble</p>
</div>
   

1 个答案:

答案 0 :(得分:0)

无论是“ If”还是“ Else”,都不显示第二个div,JS都需要正确渲染两个div,请尝试类似

<?php
  $state_val = "";
  if(isset($_GET['state_val'])){
    $state_val = $_GET['state_val'];
    print_r($state_val);
  }
  if($data['state'] == 'MA' || $state_val == 'MA'){?>
<div id="MA_st" class="uk-active">
    <li>
        <div class="uk-form-row">
            <label class="uk-form-label"><?php echo Yii::t("default","Number")?></label>
            <?php echo CHtml::textField('txt_number',
            isset($data['number'])?$data['number']:""
            ,array(
            'class'=>'uk-form-width-large'
            ))?>
        </div>

        <div class="uk-form-row">
            <label class="uk-form-label"><?php echo Yii::t("default","Name")?></label>
            <?php echo CHtml::textField('txt_name',
            isset($data['name'])?$data['name']:""
            //"ABC"
            ,array(
            'class'=>'uk-form-width-large',
            'autocomplete'=>"off"
            ))?>
        </div>
    </li>
</div>
<div id="err">
    <p>Inforamtion is not avaialble</p>
    <?php }else{?>
    <div id="MA_st">
        <li>
            <div class="uk-form-row">
                <label class="uk-form-label"><?php echo Yii::t("default","Number")?></label>
                <?php echo CHtml::textField('txt_number',
                isset($data['number'])?$data['number']:""
                ,array(
                'class'=>'uk-form-width-large'
                ))?>
            </div>

            <div class="uk-form-row">
                <label class="uk-form-label"><?php echo Yii::t("default","Name")?></label>
                <?php echo CHtml::textField('txt_name',
                isset($data['name'])?$data['name']:""
                //"ABC"
                ,array(
                'class'=>'uk-form-width-large',
                'autocomplete'=>"off"
                ))?>
            </div>
        </li>
    </div>
    <div id="err" class="uk-active">
        <p>Inforamtion is not avaialble</p>
    </div>
    }?>