簡體   English   中英

彈出窗口不起作用

[英]Popup Window not working

我試圖在我的學校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();
        });
    });
};

嘗試這個:

<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>

請注意:

  • jQuery版本已過時
  • javascript函數中做了一些更改

我希望這會有所幫助。 您可以根據自己的流程和要求進行編輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM