2017-07-14 65 views
-2

我需要jQuery腳本,當用戶在站點1分鐘後沒有向該字段輸入電子郵件時顯示彈出窗口。如果他輸入他的電子郵件,則重定向到另一個頁面。我有彈出自己。感謝您的幫助!如何在用戶沒有輸入郵件時彈出提醒

+3

你嘗試過什麼到目前爲止解釋? – AllisonC

+0

您是否嘗試過setTimeout? – T4rk1n

+0

是的,我可以設置超時,但我不能做其他事情。 – Vladimir

回答

-1

在這裏,你走了,改變的時候,你要多少秒的意思。

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<script> 
 
$(document).ready(function(){ 
 

 
var i=0; 
 
    counterControl = setInterval(function() 
 
    { 
 
    document.getElementById("clock").innerHTML=i++; 
 
    if(i==10 && $("#emailInput").val()=="") { 
 
    \t \t clearInterval(counterControl); 
 
      document.getElementById("clock").innerHTML="Time over"; 
 
      alert("You have missed the timeslot for entering email-id"); 
 
      } 
 
    else if(i>10 && !$("#emailInput").val()==""){window.location = "https://stackoverflow.com/questions";} 
 
      
 
    }, 1000); 
 

 
    
 
}); 
 
</script> 
 
</head> 
 
<body> 
 
<div id="clock">Time given: 10 seconds </div> </br> 
 

 
Enter E-mail id: <input type="text" id="emailInput"/> 
 

 

 

 

 

 
</body> 
 
</html>

-1

您可以在頁面加載時創建超時,並在觸發超時後檢查電子郵件字段是否爲空。

window.onLoad=function(){ 
    setTimeout(checkEmail,1000*60); 
}; 
function checkEmail(){ 
    if(jQuery("#idInput").val()==""){ 
     alert("pop-up"); 
     //pop-up will be show 
    } 
    else{ 
     window.location="http://www.newUrl.com"; 
     //browser will be redirect 
    } 
} 

我不知道你的彈出

+0

非常感謝,我會嘗試。 – Vladimir

0

,您可以嘗試,開始在未來降低秒一分鐘(1000米利斯)。

在這裏有一個鏈接,你可以找到有關的功能setInterval

var timetowait = (new Date().getTime()+1*60000); 
setInterval(function() { 
    var now = new Date().getTime(); 
    var oneminute = timetowait - now; 
    var seconds = Math.floor((oneminute%(1000*60))/1000);  
    if (seconds < 0) { 
     //dosomething  
    } 
}, 1000); 
相關問題