2016-12-24 27 views
0

我知道這是非常基本的,但我找不到答案。如何在一個條件內調用彈出窗口?例如:Popup.js - 調用彈出框

if(error.length != 0){ 
    console.log(error);  
    popup({ 
     content : '<p>Not allowed</p>', 
     type : 'html' 
    });   
} 

我的頁面包含一個進口

<script src="<c:url value='/resources/js/jquery.popup.min.js' />"></script> 

我得到一個錯誤:

Uncaught ReferenceError: popup is not defined

回答

0

試試這個:

if(error.length != 0){ 
    console.log(error); 
    var popup = ({ 
     content : '<p>Not allowed</p>', 
     type : 'html' 
    }); 
} 
+0

存在控制檯沒有錯誤,但一個彈出窗口不會出現 – thinker

+0

然後檢查腳本網址。我的意思是你說它是正確的? – ab29007

+0

代碼沒有顯示錯誤,也許是因爲瀏覽器。試試這個:能夠在你的瀏覽器中禁用「阻止彈出窗口」。也可以嘗試不同瀏覽器中的代碼。 – ab29007

0

我沒有看到任何直接加載在jquery.popup.min.js你可以使用color box。看到這個例子。 More demos here.

if(1){ // your condition here 
 

 
$.colorbox({html:"<h1>Welcome</h1>"}); 
 
    
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="http://www.jacklmoore.com/colorbox/example1/colorbox.css" rel="stylesheet"/> 
 
<script src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js"></script>

使用點擊LINK IN popup.js

function check(val){ 
 
     //console.log(error);  
 
     if(val != 0){ 
 
     $('.html_popup').popup({ 
 
     content : '<h1>This is some HTML for non zero</h1>', 
 
     type : 'html' 
 
    }); 
 
     }else{ 
 

 
     \t $('.html_popup').popup({ 
 
     \t  content : '<h1>This is some HTML for 0</h1>', 
 
     \t  type : 'html' 
 
     \t  }); 
 

 
     } 
 

 
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
 
    <script src="http://docs.toddish.co.uk/js/plugins/jquery.popup.min.js"></script> 
 
    <link href="http://docs.toddish.co.uk/css/plugins/popup.css" media="all" type="text/css" rel="stylesheet"> 
 
<a class="html_popup" style="width:100px;" onclick='check(1)'> click me</a>