无法删除按钮

时间:2015-10-09 20:10:00

标签: javascript php html

我在页面中有一个按钮,我发现它无法被注释掉或删除!我这样做了,整个页面显示为空。 (没有错误)

为了澄清,我需要按钮和切换的div。我的目的是为按钮添加一些auth检查,一些超级用户可以看到并使用它,但普通用户不能。我刚刚发现当我添加auth检查以隐藏普通用户的按钮时,普通用户只能看到页眉和页脚。我试图注释掉或删除按钮,发现整个页面都是空的,正如普通用户看到的那样。

我的第一个猜测是某些divformtable尚未正确结束,但似乎没有。

我的第二个猜测是一个div,当打开页面没有正确结束时它应该被隐藏但是不是,(当div点击时button会被切换我提到过)

我挖了好几个小时,但找不到真正的理由!

我在这里附上代码: 这是头部。唯一相关的部分(我相信)是$('.add')click(function(){})部分。

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script>

    $(document).ready(function() {
        $(".newsession").hide();
        $(".registration").hide();
        $(".showThisEdit").hide();

            $('.add').click(function() {
            $(".newsession").toggle(); 
            return false;
            });

            $('.editSes').click(function() {
                var showthis = $(this).attr("showthis");
                $("#show" + showthis).toggle();
                return false;
            }); 

            $(".show").click(function(){
                var show = $(this).attr("show");
                $("#" + show).toggle();
                return false;
            });
        });


    $(function() {
    $( ".datepickersession" ).datepicker();
    }); 


    </script>

这是身体:

<!--Add New Sessions-->
<div class = 'container'>
<!--This BUTTON!!!-->
<button style ='color:blue' class = 'add' >Add New Sessions</button><br>

<div class = 'newsession' style = 'border-style: solid; border-width: 1px;'>
<div class = 'container'>
<form method = 'POST'>
<br>
<label>Term</label><input type = "text" name = "Term" value = "<?php echo $TermCheckRow['strm'];?>"><br>
<!--We have a lot of labels-->
<button type='submit' class = 'btn btn-primary' name = 'saveSession' value = 'saveSession'>Save</button>
<button type='submit' class = 'btn btn-danger' name = 'cancleaddSession' >Cancel</button>
</form><br>
</div>
</div><br>
<!--End of Add New Sessions-->

<!--Here we write into DB-->
<?php
    if (isset($_POST['saveSession'])){
    //our build in db connection functions
    }
?>

<!--And here there is a form-->
<form><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table></form>

</div>

当我删除按钮部分

<button style ='color:blue' class = 'add' >Add New Sessions</button><br>

我得到了空白页面,我检查了源代码。它是这样的: 头是一样的。

这是正文:我有一个非常大的表格,为了节省您的时间,我只是删除这些代码。

    <!--Add New Sessions-->
    <div class = 'container'>


    <div class = 'newsession' style = 'border-style: solid; border-width: 1px;'>
    <div class = 'container'>
    <form method = 'POST'>
    <br>
    <label>Term:&nbsp;</label><input type = "text" name = "Term" value = "2159"><br>
    <label>Date:&nbsp;</label><input type = "text" class = "datepickersession" name = "SessionDate"><br>
    <label>Time Begin:&nbsp;</label><input type = "text" name = "TimeBegin" placeholder= "e.g.: 9:00am"><br>
    <label>Time End:&nbsp;</label><input type = "text" name = "TimeEnd" placeholder= "e.g.: 9:00am"><br>
    <label>Cut Off Date:&nbsp;</label><input type = "text" class = "datepickersession" name = "CutDate"><br>
    <label>Max Capacity:&nbsp;</label><input type = "text" name = "MaxCap" value = "20"><br>
    <label>Location:&nbsp;</label><input type = "text" name = "Location">
    <br>
    <label>Hide:&nbsp;</label><input type = 'checkbox' name = "Hide"><br>
    <button type='submit' class = 'btn btn-primary' name = 'saveSession' value = 'saveSession'>Save</button>
    <button type='submit' class = 'btn btn-danger' name = 'cancleaddSession' >Cancel</button>
    </form><br>
    </div>
    </div><br>
    <!--End of Add New Sessions-->
<form class='form-horizontal' method='POST'>
</form></div></div>


</body> 
</html>

但页面是空的!

有人可以看一下吗? 非常感谢!

得到一些提示......

生成页面时,已经构建了<html><head></head><body></body></html>

我删除所有新添加的标签并在此处更新我的代码。

但是,它仍然不起作用!

2 个答案:

答案 0 :(得分:0)

<head>标记中的javascript更改为:

$(document).ready(function() {
    $(".registration").hide();
    $(".showThisEdit").hide();

    $('.editSes').click(function() {
        var showthis = $(this).attr("showthis");
        $("#show" + showthis).toggle();
        return false;
    });

    $(".show").click(function() {
        var show = $(this).attr("show");
        $("#" + show).toggle();
        return false;
    });
});


$(function() {
    $(".datepickersession").datepicker();
});

答案 1 :(得分:0)

谢谢hopkins-matt。从你的评论中,我意识到除非我们注释掉所有与JS相关的函数,否则不可能注释掉链接到JS函数的按钮。虽然它不理想,但我仍然通过为普通用户添加禁用的隐藏按钮来解决问题。代码在这里:

<?php if (Auth::hasPermissionIn(array('admin', 'super-user'))){ ?>
<button style ='color:blue' class = 'add' >Add New Sessions</button><br>
<?php } ?>

<?php if (Auth::hasPermissionIn(array('plain-user'))) { echo "<button class = 'add' style = 'border:none' disabled ></button>";} ?>

这样,带有class =&#39;添加&#39;的按钮仍然存在,但普通用户既不能看到也不能点击它。

谢谢大家!

相关问题