如何创建自定义事件并使用Javascript启动它

How do I create a custom event and fire it using Javascript

本文关键字:Javascript 启动 事件 自定义 何创建 创建      更新时间:2024-01-07

我的代码:。。。。。

<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事件火自动关闭并关闭它。

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

这是一把小提琴。(点击两种颜色打开和关闭警报。

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');
});