简体   繁体   English

隐藏文件上传按钮

[英]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. 它的工作方式是这样的:当我找到一个带有“ R”类型的档案时,我必须隐藏相关的按钮。 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. 因此,我所做的就是将按钮放在ID为“ hayResolucion ”的div中,因此一旦找到“ R”类型的存档,就将其隐藏。 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.. 您可以在HTML生成时添加此检查吗?

<?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.. 用PHP生成HTML和JS都是没有意义的,在完成JS来隐藏HTML之后,也没有用。

Looks fine to me, you just need to wrap it up inside document.ready func 对我来说看起来不错,您只需要将其包装在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 也许您应该确保已加载DOM

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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