看到它只有一个按钮并且我使用window.location.href = 'pagehere.html';
看起来真的很简单它可能看起来很简单,但很多帮助将会受到赞赏。我对此有点新意,如果它很简单,请给我一些懈怠。
这是代码,HTML,CSS和JavaScript。
var logpopup = document.getElementById('Login_Popup');
/* creating variables and calling ID's from HTML document */
var logbutton = document.getElementById('Login_Button');
/**/
var span = document.getElementsByClassName('popup_x')[0];
/**/
var registerlink = document.getElementById('Register_Button');
/*
var username,x,y;
*/
/**/
logbutton.onclick = function() {
"use strict"; /* should be run in strict mode */
logpopup.style.display = 'block';
/* if "logbutton" is clicked, display "logpopup" */
};
span.onclick = function() {
"use strict";
logpopup.style.display = 'none';
/* if "span" is flicked, close/do not display "logpopup" */
};
window.onclick = function() {
/* (window is a default variable) If event running is "logopopup" and window is clicked, close/do not display logopopup */
"use strict";
if (event.target === logpopup) {
logpopup.style.display = 'none';
}
};
/*
function outputname() {
x=document.getElementById("popup_form");
y=x.elements["username"].value; not working yet
name = "John";
document.write("Hello "+y+"<br>");
}
*/
registerlink.onclick = function() {
/* when "registerlink" is clicked, call "Test3Register.html" */
"use strict";
window.location.href = 'CarCompanyRegister.html';
return;
};
var registersubmitvalidate = document.getElementById('register_button_validation');
registersubmitvalidate.onclick = function() {
"use strict";
window.location.href = 'CarCompany.html';
return;
};
var dropdownArray = ['dropdown_content1', 'dropdown_content2', 'dropdown_content3', 'dropdown_content4', 'dropdown_content5', 'dropdown_content6', 'dropdown_content7', 'dropdown_content8', 'dropdown_content9'];
window.addEventListener('mouseup', function(event) {
"use strict";
for (var i = 0; i < dropdownArray.length; i++) {
var rightdropdown = document.getElementById(dropdownArray[i]);
if (event.target != rightdropdown) {
rightdropdown.style.display = 'none';
}
}
});
window.onload = function() {
"use strict";
var dict = {
'left_side_button1': 'dropdown_content1',
'left_side_button2': 'dropdown_content2',
'left_side_button3': 'dropdown_content3',
'mid_side_button4': 'dropdown_content4',
'mid_side_button5': 'dropdown_content5',
'mid_side_button6': 'dropdown_content6',
'right_side_button7': 'dropdown_content7',
'right_side_button8': 'dropdown_content8',
'right_side_button9': 'dropdown_content9'
}
document.onclick = function(e) {
for (var l in dict) {
if (e.target === document.getElementById(l)) {
document.getElementById(dict[l]).style.display = 'block';
}
}
}
};
&#13;
button,
p,
h1,
h2,
h3,
h4,
h5,
a {
/* State that these particular elements be "fantasy" */
font-family: Tahoma;
}
#main_body {
margin: 0px auto;
background-color: #dedede;
}
#top_body {
/* for the sake of having no margin */
}
#top_container {
text-align: left;
margin: 4px;
padding: 0px;
/*background-image: -webkit-radial-gradient(left top, ellipse farthest-side, #8CFBFF 0%, #FFFFFF 100%); */
background: -webkit-linear-gradient(#666, #000);
position: relative;
color: aliceblue;
}
#top_header {
margin: 0px auto;
padding: 0px auto;
box-shadow: 3px 3px 3px grey;
text-decoration: none;
}
#header_hgroup li {
display: inline-block;
list-style: none;
text-decoration: none;
}
.header_text {
padding-right: 20px;
padding-left: 20px;
}
#Login_Button {
float: right;
height: 80px;
width: 80px;
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
border: 0px;
-moz-border-radius-topleft: 15px;
border-top-left-radius: 15px;
-moz-border-radius-bottomleft: 15px;
border-bottom-left-radius: 15px;
}
#Register_Button {
float: right;
height: 80px;
width: 80px;
background-color: white;
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
border: 0px;
}
#top_nav {
text-decoration: none;
border-bottom: 1px solid black;
padding: 0px;
margin: 0px auto;
box-shadow: 3px 3px 3px grey;
text-align: left;
position: static;
margin-bottom: 10px;
}
#top_nav li {
display: inline-block;
text-decoration: none;
}
#nav1 {
border: 1px solid white;
margin-left: 0px;
}
.class1 {
display: none;
}
.mid_container {
margin: 0px auto;
overflow: auto;
width: 1000px;
display: block;
background-color: white;
border: 1px solid black;
align-content: center;
margin-bottom: 105px;
}
#container_top_padder {
padding-top: 10px;
padding-bottom: 10px;
margin-right: 50px;
margin-left: 50px;
text-align: center;
border-bottom: 2px solid black;
}
#container_top_padder li {
text-decoration: none;
display: inline-block;
font-weight: none;
}
#individual_top_padder_text {
margin: 0px auto;
}
#vehicle_1_header {
/* not assigned at the moment */
margin-left: 5px;
margin-right: 5px;
margin-top: 5px;
margin-bottom: 0px;
padding: 0px;
background-image: -webkit-radial-gradient(left top, ellipse farthest-side, #8CFBFF 0%, #FFFFFF 100%);
width: 100px;
float: left;
border-bottom: 2px solid black;
}
#vehicle_2_header {
/* not assigned at the moment */
margin-left: 5px;
margin-right: 5px;
margin-top: 5px;
margin-bottom: 0px;
padding: 0px;
background-image: -webkit-radial-gradient(left top, ellipse farthest-side, #8CFBFF 0%, #FFFFFF 100%);
width: 100px;
float: left;
border-bottom: 2px solid black;
}
#vehicle_3_header {
/* not assigned at the moment */
margin-left: 5px;
margin-right: 5px;
margin-top: 5px;
margin-bottom: 0px;
padding: 0px;
background-image: -webkit-radial-gradient(left top, ellipse farthest-side, #8CFBFF 0%, #FFFFFF 100%);
width: 100px;
float: right;
border-bottom: 2px solid black;
}
.compare_sections_titles {
/* not assigned at the moment */
margin-left: 2px;
margin-right: 2px;
margin-top: 2px;
margin-bottom: 0px;
display: inline-block;
}
#left_section {
margin-left: 15px;
margin-right: 5px;
margin-bottom: 0px;
margin-top: 5px;
float: left;
text-align: center;
padding-top: 20px;
padding-bottom: 48px;
width: 300px;
background-color: white;
box-shadow: 4px 4px 4px #888;
-moz-border-radius-topleft: 10px;
border-top-left-radius: 10px;
}
#left_side_button1 {
/*background-color: aqua; */
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
margin-bottom: 20px;
}
#dropdown_content1 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content1 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#dropdown_content1 a:hover {
background-color: #f1f1f1;
}
#left_side_button2 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
margin-bottom: 20px;
}
#dropdown_content2 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content2 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#dropdown_content2 a:hover {
background-color: #f1f1f1;
}
#left_side_button3 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
}
#dropdown_content3 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content3 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#dropdown_content3 a:hover {
background-color: #f1f1f1;
}
#mid_section {
margin-left: 25px;
margin-right: 5px;
margin-bottom: 15px;
margin-top: 5px;
float: left;
text-align: center;
padding-top: 20px;
padding-bottom: 50px;
width: 300px;
background-color: white;
box-shadow: 4px 4px 4px #888;
-moz-border-radius-topleft: 10px;
border-top-left-radius: 10px;
}
#mid_side_button4 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
margin-bottom: 20px;
}
#dropdown_content4 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content4 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown_all_text {
color: black;
text-align: center;
}
#dropdown_content4 a:hover {
background-color: #f1f1f1
}
#mid_side_button5 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
margin-bottom: 20px;
}
#dropdown_content5 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content5 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#dropdown_content5 a:hover {
background-color: #f1f1f1
}
#mid_side_button6 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
}
#dropdown_content6 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content6 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#dropdown_content6 a:hover {
background-color: #f1f1f1
}
#right_section {
margin-right: 15px;
margin-bottom: 0px;
margin-top: 5px;
float: right;
text-align: center;
padding-top: 20px;
padding-bottom: 50px;
width: 300px;
background-color: white;
box-shadow: 4px 4px 4px #888;
-moz-border-radius-topleft: 10px;
border-top-left-radius: 10px;
}
#right_side_button7 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
margin-bottom: 20px;
}
#dropdown_content7 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content7 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#dropdown_content7 a:hover {
background-color: #f1f1f1;
}
#right_side_button8 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
margin-bottom: 20px;
}
#dropdown_content8 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
z-index: 10000;
}
#dropdown_content8 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#dropdown_content8 a:hover {
background-color: #f1f1f1;
}
#right_side_button9 {
background: -webkit-linear-gradient(#ffffff, #c6c6c6);
padding-right: 90px;
padding-left: 90px;
font-size: 16px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px #888;
}
#dropdown_content9 {
display: none;
overflow: hidden;
position: absolute;
background-color: #f9f9f9;
min-width: 220px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-left: 40px;
text-align: left;
}
#dropdown_content9 a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#compare_dialog_container {
margin: 0px auto;
display: block;
width: 1000px;
border: 2px solid black;
text-align: center;
}
#compare_dialog_container li {
text-decoration: none;
font-weight: none;
list-style: none;
display: inline-block;
}
#Red_compare_button {
color: white;
background: -webkit-linear-gradient(#ff3e3e, #ff0000);
padding: 10px;
}
#dropdown_content9 a:hover {
background-color: #f1f1f1;
}
.popup_container {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/ opacity */
}
.popup {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 2px solid #888;
width: 25%;
border-radius: 28px;
/* Stating that all corners should be rounded */
-moz-border-radius: 28px;
/*<*/
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s;
text-align: center;
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {
top: -300px;
opacity: 0
}
to {
top: 0;
opacity: 1
}
}
@keyframes animatetop {
from {
top: -300px;
opacity: 0
}
to {
top: 0;
opacity: 1
}
}
.popup_x {
color: grey;
float: right;
font-size: 28px;
font-weight: bold;
}
.popup_x:hover {
color: black;
text-decoration: none;
cursor: pointer;
}
.popup_head {
padding: 2px 16px;
background-image: -webkit-radial-gradient(left top, ellipse farthest-side, lightblue 0%, white 100%);
color: black;
box-shadow: 2px 2px 2px #888;
text-align: center;
-moz-border-radius-topright: 25px;
border-top-right-radius: 25px;
-moz-border-radius-topleft: 25px;
border-top-left-radius: 25px;
}
.popup_bod {
padding: 2px 16px;
}
.loginform_bod_text {
font-weight: bold;
}
.popup_foot {
padding: 2px 16px;
color: white;
-moz-border-radius-bottomright: 25px;
border-bottom-right-radius: 25px;
-moz-border-radius-bottomleft: 25px;
border-bottom-left-radius: 25px;
background-image: -webkit-radial-gradient(bottom right, ellipse farthest-side, lightblue 0%, white 100%);
border-top: 1px solid #888;
}
.loginform_foot_text {
color: black;
font-weight: none;
text-decoration: none;
font-style: none;
border-top: 2px solid black;
text-align: center;
}
.loginform_foot_text:hover {
text-decoration: underline;
}
#mid_container_register {
margin: 0px auto;
overflow: auto;
width: 1000px;
display: block;
background-color: white;
align-content: center;
margin-bottom: 105px;
padding: 20px;
border: 1px solid black;
}
#register_section {
margin: 0px auto;
overflow: auto;
box-shadow: 4px 4px 4px #888;
background-color: white;
padding-left: 10px;
padding-right: 10px;
margin-right: 10px;
margin-bottom: 10px;
border-left: 1px solid grey;
}
.Register_subtitle {
color: #999999;
}
.Single_span_text_coloring {
color: #0000CC;
font-weight: bolder;
}
#register_article_footer {
color: gray;
}
#left_side_nav {
float: left;
width: 200px;
box-shadow: 4px 4px 4px #888;
margin-right: 75px;
background-color: white;
}
#left_side_nav a {
text-decoration: none;
list-style: disc;
font-weight: none;
color: black;
}
#left_side_nav a:hover {
text-decoration: underline;
cursor: default;
}
#bottom_container {
clear: both;
text-align: center;
padding: 10px;
border-top: 1px solid;
background: white;
color: black;
text-align: center;
font-weight: bold;
}
.show {
display: block!important;
}
&#13;
<html>
<body id="main_body">
<head>
<title>Home</title>
<link rel="stylesheet" href="CarCompanyCSS.css">
<meta name="viewpoint" content="width=deive-width" />
<script type="text/javascript" src="CarCompanyJavascript.js"></script>
</head>
<div id="top_container">
<header id="top_header">
<hgroup id="header_hgroup">
<a class="header_text">
<li>
<h1>Title</h1>
</li>
</a>
<!-- Add specificity if needed -->
<a class="header_text">
<li>
<h3>Subtitle</h3>
</li>
</a>
<button id="Login_Button">Login</button>
<div id="Login_Popup" class="popup_container">
<!-- Popup creation -->
<div class="popup">
<div class="popup_head">
<span class="popup_x">x</span>
<h2>Login</h2>
</div>
<div class="popup_bod">
<form>
<br />
<label>Username:</label><br />
<input class="loginform_bod_text" type="text" name="Username" maxlength="10" placeholder="Username" /><br />
<label>Password:</label><br />
<input class="loginform_bod_text" type="password" name="Password" maxlength="20" placeholder="Password" />
<br />
<br />
<input type="submit" value="Login" />
</form>
</div>
<div class="popup_foot">
<br />
<a class="loginform_foot_text" href="Forgot Password.html">Reset Password</a>
<br />
</div>
</div>
</div>
</hgroup>
</header>
<nav id="top_nav">
<ul>
<li><a id="nav1">Cars</a></li>
</ul>
</nav>
</div>
<div id="mid_container_register">
<hr />
<section id="left_side_nav">
<article>
<nav>
<ol>
<a href="CarCompany.html">
<li>Home</li>
</a>
<hr />
<a href="CarCompany.html">
<li>My Account</li>
</a>
<hr />
<a href="CarCompany.html">
<li>Category</li>
</a>
</ol>
</nav>
</article>
</section>
<section id="register_section">
<header>
<hgroup>
<h3><u><b>Register</b></u></h3>
<p>
<h5 class="Register_subtitle">To submit, all fields must be completed.</h5>
</p>
<p>
<h5 class="Register_subtitle"> Fields marked with a <span class="Single_span_text_coloring"> * </span> are required</h5>
</p>
<hr />
<br />
</hgroup>
</header>
<form>
<label>Username:</label>
<br /><input type="text" name="Username" maxlength="10"><span class="Single_span_text_coloring"> * </span><br /><br />
<label>Password:</label>
<br /> <input type="password" name="Password" maxlength="16"><span class="Single_span_text_coloring"> * </span><br /><br />
<label>E-Mail:</label>
<br /> <input type="text" name="E-Mail"><span class="Single_span_text_coloring"> * </span><br /><br />
<label>Age:</label>
<br /> <select type="option" name="Age">
<option></option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
</select><br /><br />
<p>Security Question:</p><br /><select type="select" name="Security Question">
<option>Please select one.</option>
<option>What was my school teachers first name?</option>
<option>Whats my favourite chip flavour?</option>
<option>What type was my first car?</option>
<option>What was the name of my first school?</option>
<option>What are my parents names?</option>
<option>How many siblings do i have?</option>
<option>What was the address of my first house?</option>
</select><br /> <br />
<p>Answer:</p> <br /> <input type="text" name="Answer">
<button>Why</button><br /><br />
<button id="register_button_validation">Submit</button>
<!-- Not working... -->
</form>
<footer id="register_article_footer">
<p>Check your mail to validate your account</p>
</footer>
</section>
<br />
<hr />
</div>
<script type="text/javascript" src="CarCompanyJavascript.js"></script>
</body>
</html>
&#13;
答案 0 :(得分:2)
document.getElementById('Register_Button');
html中唯一接近的ID为register_button_validation
,因此getElementById("some_non_existing_id")
会返回null
。而且您无法在onclick
上设置null
方法。
作为抛出的异常,无法执行剩余的代码,并且registersubmitvalidate.onclick
无法绑定,因此无法执行此函数:
registersubmitvalidate.onclick = function() {
"use strict";
window.location.href = 'CarCompany.html';
return;
};