gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:42:12 24 4
gpt4 key购买 nike

我正在根据 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com