0
我试图让标题在“Board Certified整形外科医生,Landon Keith”和“Landon Keith,董事会认证的整形外科医生”之间切换,但没有任何事情发生,它看起来像onload
功能未运行Javascript onload功能未运行
Ex。当我点击图片时,头部显示会显示“Board Certified整形外科医生Landon Keith”,当我再次点击图片时,应该说“Board Certified整形外科医生,Landon Keith”等等。
我的代码如下:
var p = document.getElementById('pic');
var h = document.getElementById('head');
alert("oh");
window.onload=function(){
\t alert("inonload"); // This alert function is not showing up
\t p.onclick = function(){
\t \t if (sessionStorage["clicked"] == "true"){
\t \t \t alert ("if");
\t \t \t sessionStorage["clicked"] = "false";
\t \t \t h.innerHTML = "Board Certified Plastic Surgeon, Landon Keith";
\t \t }else{
\t \t \t alert ("else");
\t \t \t sessionStorage["clicked"] = "true";
\t \t \t h.innerHTML = "Landon Keith, Board Certified Plastic Surgeon";
\t \t }
\t };
};
alert("end");
body{
\t margin-bottom: 100px;
\t margin-right: 20px;
\t margin-left: 20px;
\t margin-top: 10px;
\t background-color: green;
\t font-family:Helvetica;
}
.navBar {
\t background-colour: red;
\t
}
#pagewrap {
\t background-color: yellow;
\t height: 280px;
\t width: 640px;
\t margin-left: auto;
\t margin-right: auto;
\t padding-top: 25px;
}
ul {
\t padding-left: 10px;
\t background-color: red;
\t list-style: none;
}
ul li {
\t display: inline;
}
ul li a {
\t text-decoration:none;
\t color:white;
}
img {
\t float: right;
\t padding-right: 20px;
}
h1 {
\t margin-left: 25px;
\t font-size: 14pt;
}
ol {
\t margin-left: 25px;
}
p {
\t margin-left: 25px;
}
<!DOCTYPE html>
<html>
<head>
<title>Keith and Company</title>
<link rel="stylesheet" type="text/css" href="css.css">
<script src='js.js'></script>
</head>
<body onload="init()">
\t <div id=pagewrap>
\t \t <img id="pic" src=image.png></img>
\t \t <ul>
\t \t \t <li class="navBarItem"><a href="#3">Reconstructive Surgery</a></li>
\t \t \t <li class="navBarItem"><a href="#4">Cosmetic Surgery</a></li>
\t \t \t <li class="navBarItem"><a href="#5">Awards</a></li>
\t \t \t <li class="navBarItem"><a href="#6">Testimonials</a></li>
\t \t </ul>
\t \t
\t \t <h1 id="head" >Landon Keith, Board Certified Plastic Surgery</h1>
\t \t <ol>
\t \t \t <li> M.D., <a href="#1"> University of SomeState></a></li>
\t \t \t <li> Specialization. <a href="#2"> John Hide></a></li>
\t \t </ol>
\t \t <p>
\t \t \t Keith and Company<BR>
\t \t \t 111 Street Name<BR>
\t \t \t Town, State, Postal Code<BR>
\t \t </p>
\t </div>
\t
</body>
您的代码是否达到'结束'提醒?你还可以检查控制台,看看是否有任何错误? –
你在控制台上看到任何错误吗?在chrome上按F12来查看控制台 –
很确定onload =“init()”覆盖window.onload = function(){} – emed