javascript - 为什么该函数没有被调用?

标签 javascript html

我正在根据 URL 测试一个东西。如果 URL 以 logout.jsp 结尾,则应显示注销消息 如果 URL 以 index.jsp 结尾,则不应显示该消息。为此我使用了 document.getElementById("id").hidden = value。但这不起作用。事实上该函数没有被调用。 我不知道问题出在哪里。

HTML 片段

<table id="LogoutMessage" onload="urlCheck()">
            <tr>
                <td>
                    <h2>You are successfully logged out !</h2>
                </td>
            </tr>
        </table>

javascript函数

<script type="text/javascript">
    function urlCheck() {
        alert("in the function urlCheck");
        if(document.URL.endsWith() = "logout.jsp")
            document.getElementById("LogoutMessage").hidden = false;
        else if(document.URL.endsWith() = "index.jsp")
            document.getElementById("LogoutMessage").hidden = true;                
    }
</script>

整个页面 在 JSP 中

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>PhotoArtWork</title>
    <jsp:include page="reusable/stylesheets.html" />
    <script type="text/javascript" src="js/modernizr-1.5.min.js"></script>
</head>
<body>
    <jsp:include page="reusable/header.html" />
    <!-- begin content --><div id="site_content">
        <table id="LogoutMessage" onload="urlCheck()">
            <tr>
                <td>
                    <h2>You are successfully logged out !</h2>
                </td>
            </tr>
        </table>
  <ul class="slideshow">
    <li class="show"><img width="950" height="450" src="images/home_1.jpg" alt="&quot;You can put a caption for your image right here&quot;"></li>
    <li><img width="950" height="450" src="images/home_2.jpg" alt="&quot;You can put a description of the image here if you like, or anything else if you want.&quot;"></li>
    <li><img width="950" height="450" src="images/home_3.jpg" alt="&quot;You can put a description of the image here if you like, or anything else if you want.&quot;"></li>

  </ul>
  </div>
<!-- end content -->
<script type="text/javascript">
    function urlCheck() {
        alert("in the function urlCheck");
        if(document.URL.endsWith() = "logout.jsp")
            document.getElementById("LogoutMessage").hidden = false;
        else if(document.URL.endsWith() = "index.jsp")
            document.getElementById("LogoutMessage").hidden = true;                
    }
</script>
<jsp:include page="reusable/footer.html" />
</body>
</html>

问题是什么?

最佳答案

没有 .hidden 属性。它是元素样式的一部分,您将使用可见性。

document.getElementById("LogoutMessage").style.visibility = "hidden"; // or "visible"

如果我不得不猜测,您想使用显示而不是隐藏

document.getElementById("LogoutMessage").style.display = "none"; // or "block"

关于javascript - 为什么该函数没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10268391/

相关文章:

javascript - Href 在 Chrome 中不工作,在 IE 中工作

javascript - getElementsByTagName 排除脚本标签

javascript - 如何使用innerHTML在<p>标签中显示jquery datepicker值

html - 正确创建文章部分

html - 可以在大多数使用 html5 的现代浏览器中播放视频格式和视频和音频编解码器的哪些组合?

javascript - 动态创建异步函数

JavaScript ajax(获取)

html - 悬停时的图标动画

javascript - 使用 Node JS 在 Firebase 托管中单独路由

javascript - css在不同维度上的定位不同