我试图在“弹出”按钮被按下时弹出一个窗口,作为我学校 Javascript 作业的一部分,但无法弄清楚为什么我的代码不起作用。我已将弹出按钮分配给 jQuery 选择器,但它仍然无法打开。
<html>
<head>
<title>Adam Ginther's Pop-up Window</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="panel">
Congrats! You won!
</div>
<div id="centreblock">
<h1>WOW! AMAZING!!!</h1>
<img src="images/ipad.gif" width="100%" height="250">
<p>Congratulations! You won a free iPad! Enter your name, address, and phone number to have it delivered now.
<form action="">
<br>
<label for="firstName">First Name: </label>
<input type="text" size="12" id="firstName" name="firstName">
<br>
<br>
<label for ="lastName">Last Name: </label>
<input type="text" size"12" id="lastName" name="lastName">
<br>
<br>
<label for="address">Address: </label>
<input type="text" size="12" id="address" name="address">
<br>
<br>
<label for="phoneNum">Phone Number: </label>
<input type="text" size="12" id="phoneNum" name="phoneNum">
</form>
<br>
<a href="#" id="popup"><br>REDEEM THIS SPECTACULAR OFFER NOW!</a>
<br>
</div>
<script src="http//code.jquery.com/jquery-latest.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>
//script.js
var new_win;
var firstName;
var lastName;
var address;
var phoneNumber;
function newWindow() {
firstName = $('#firstName').val();
if (firstName !='') {
window.open('popup.html');
} else {
$('#firstName').addClass('error');
};
$(function() {
$('#popup').click(function() {
newWindow();
});
});
};