Popup.js - 调用弹出窗口

时间:2016-12-24 08:27:40

标签: javascript jquery popup

我知道这是非常基本的,但我找不到答案。如何在条件下调用弹出窗口?例如:

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>

我收到错误:

  

未捕获的ReferenceError:未定义弹出窗口

2 个答案:

答案 0 :(得分:0)

试试这个:

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

答案 1 :(得分:0)

我在jquery.popup.min.js中看不到任何可以使用color box的直接加载。请参阅示例。More demos here.

&#13;
&#13;
if(1){ // your condition here

$.colorbox({html:"<h1>Welcome</h1>"});
  
  }
&#13;
<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>
&#13;
&#13;
&#13;

在popup.js中使用点击链接

&#13;
&#13;
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{

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

        }

}   
&#13;
<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>
&#13;
&#13;
&#13;