duanche8554 2017-05-02 01:17
浏览 38
已采纳

使用Javascript函数隐藏PHP内的按钮

I am currently writing a website where I want to hide the the supervisor editing button if the supervisor field = N. I am able to get the query to display the correct output but I can't get the button to hide. Can anyone help me get it to hide whenever the page loads. I also under stand I should be using PDO's but we have not been taught that sadly.

HTML & PHP

        <?php

        $supervisorstatus = mysql_fetch_assoc($supervisorresult);
        echo $supervisorstatus['supervisor'];
                                if($supervisorstatus !='Y') {
                                    echo '<script type="text/javascript">',
     'closesup();',
     '</script>'
;
                                } 


        ?>

JavaScript

function closesup(){
    document.getElementById('supervisor').style.visibility="hidden";
}

Supervisor is the element id for the button.

  • 写回答

2条回答 默认 最新

  • douzhangli9563 2017-05-02 01:23
    关注

    This is how your code would be

        <?php
    
                $supervisorstatus = mysql_fetch_assoc($supervisorresult);
                echo $supervisorstatus['supervisor'];
                                        if($supervisorstatus['supervisor'] !='Y') {
                                            echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("#supervisor").hide();
    });
    </script>';        
    
                                        } 
    
    
                ?>
    

    I gave a example of implementation above but if you need to see it separate Here is the code to hide your supervisor id

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("#supervisor").hide();
    });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!