如何创建自定义事件并使用Javascript触发它

时间:2013-12-02 04:30:12

标签: javascript html html5

我的代码:.....

<html>
<head>
<script>
function demo()
{
    var win=window.open("demo.html",'_blank');
    alert('Requested Page Loaded...');
    win.focus();
}
</script>
</head>
<body>
<input type="button" value="demo" onClick="demo()"></input>
</body>
</html>

我想使用JavaScript事件动态关闭警报事件。 当看到警报时,它将使用JavaScript事件自动关闭并关闭它..

1 个答案:

答案 0 :(得分:1)

您可以创建一个伪警报。 如果它被编程事件(而不是屏幕触发)关闭,您可以将其设为模态。

HERE是一个小提琴。 (单击两种颜色可打开和关闭警报。

HTML

<div class='testdiv'></div>
<div class='testdiv3'></div>
<div id='dialogtest' class='testdiv2'>Alert!</div>

CSS

.testdiv {
    width: 100px;
    height: 100px;
    margin: 0px auto;
    background-color: red;
}
.testdiv3 {
    width: 100px;
    height: 100px;
    margin: 0px auto;
    background-color: green;
}

.testdiv2 {
    background-color: green;
    width: 50px;
    height: 50px;
    font-size: 15px;
}
.ui-dialog-titlebar {
    display: none;
}

JS

$( ".testdiv2" ).dialog({
                       autoOpen: false,
                          modal: false,
                         height: 50,
                          width: 'auto',
                       position: { my: "right middle",
                                   at: "left middle",
                                  of : ".testdiv" } 
                           });

$('.testdiv').click(function(){
  $('.testdiv2').dialog('open');
});
$('.testdiv3').click(function(){
  $('.testdiv2').dialog('close');
});
相关问题