简体   繁体   English

弹出窗口不起作用

[英]Popup Window not working

I am trying to make a window pop up when the "popup" button is pressed as a part of my Javascript assignment for school but can't figure out why my code isn't working. 我试图在我的学校Javascript分配中按下“弹出”按钮时弹出一个窗口,但无法弄清楚为什么我的代码无法正常工作。 I've assigned the popup button to a jQuery selector and it still will not open. 我已将弹出按钮分配给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();
        });
    });
};

try this: 尝试这个:

<html>
<head>
<title>Adam Ginther's Pop-up Window</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="js/script.js"></script>
<script language="javascript">


//script.js
var new_win;
var firstName;
var lastName;
var address;
var phoneNumber;

function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if (window.focus) {newwindow.focus()}
    return false;
}

function newWindow() { 
    firstName = $('#firstName').val();
    if (firstName !='') {
    popitup('popup.html');
    } else {
        $('#firstName').addClass('error');
    };
};

    $(document).ready(function(){
        $('#popup').click(function() {
            newWindow();
        });
    });
</script>
</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="javascript:void(0)" id="popup"><br>REDEEM THIS SPECTACULAR OFFER NOW!</a>
<br>
</div>
</body>
</html>

please note: 请注意:

  • The jquery version was outdated jQuery版本已过时
  • there are some changes done in the javascript function javascript函数中做了一些更改

I hope this might help. 我希望这会有所帮助。 You can edit as per your flow and requirement. 您可以根据自己的流程和要求进行编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM