简体   繁体   中英

hiding file upload button

I'm having troubles hiding an option. It works like this: when I find an archive with an 'R' type, I have to hide the related button. So what I did was put the button in a div with id " hayResolucion ", so once I find an 'R' type archive, I just hide it. Here is the code:

<div id="hayResolucion" name="hayResolucion">
    <td colspan="3" align="left" valign="middle" class="sangrar">Archivo Resolución:
        <input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
        <input type="file" name="archivo_r"/>
    </td>
</div>

and here is the function that it's supposed to hide it:

<?php if($row_archivos['tipo']=='R'){ ?>
  <script>
      $(document).ready(function(){
        $("#hayResolucion").hide();
      });
  </script>
<?php } ?>

Instead of making:

<?php if($row_archivos['tipo']=='R'){ ?>
  <script>

Can you add this check at the HTML generation..

<?php if($row_archivos['tipo']!='R'){ ?>
  <div id="hayResolucion" name="hayResolucion">

or even with inline check.

<div id="hayResolucion"
    <?=$row_archivos['tipo']=='R'?'style="display:none;"':''?> name="hayResolucion">

There is no point to generate both HTML and JS with PHP and after its finished the JS to hide the HTML..

Looks fine to me, you just need to wrap it up inside document.ready func

<?php if($row_archivos['tipo']=='R'){ ?>
  <script>
   $(document).ready(function(){
     $(document).find('#hayResolucion').hide();
   });
  </script>
<?php } ?>

Perhaps you should make sure the DOM is loaded

<?php if($row_archivos['tipo']=='R') : ?>
<script type="text/javascript">
$(document).ready(function() {
    $('#hayResolucion').hide();
});
</script>
<?php endif;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM