Jquery CSS";onclick";伪类不起作用

Jquery CSS";onclick";伪类不起作用,jquery,css,html,Jquery,Css,Html,此代码是从中提取的,经过一些修改 我的目的是在用户单击拐角处的[x]按钮时显示模式窗体并将其关闭,或在10秒后自动关闭 唯一的问题是,当我单击[x]按钮时,表单无法关闭。下面的代码有什么问题 index.html: <html> <head> <link href="style.css" rel="stylesheet"> <script src="jquery.min.js"></script> </head> <b

此代码是从中提取的,经过一些修改

我的目的是在用户单击拐角处的[x]按钮时显示模式窗体并将其关闭,或在10秒后自动关闭

唯一的问题是,当我单击[x]按钮时,表单无法关闭。下面的代码有什么问题

index.html:

<html>
<head>
<link href="style.css" rel="stylesheet">
<script src="jquery.min.js"></script>
</head>
<body>
<div id="openModal" class="modalDialog">
    <div>
        <a href="#close" title="Close" class="close">X</a>
           Hi, this is modal form.
    </div>
</div>

<script type="text/javascript">
        setTimeout(function() {
          $('#openModal').fadeOut('slow'); }, 10000); 
</script>

</body>
</html>

您应该在关闭按钮的单击事件处理程序中调用淡出/关闭方法。

您需要添加

jQuery(function($){
    $('#openModal .close').click(function(){
        $('#openModal').fadeOut('slow'); 
    }); 
})

演示:

这是一个工作示例,将下面的代码保存为.HTML文件并使用它

<html>
<head>
<title></title>
<style type="text/css">
.modalDialog {
-moz-transition: opacity 400ms ease-in 0s;
background: none repeat scroll 0 0 rgba(0, 0, 0, 0.8);
bottom: 0;
font-family: Arial,Helvetica,sans-serif;
left: 0;
opacity: 0;
pointer-events: none;
position: fixed;
right: 0;
top: 0;
z-index: 99999;
}

.modalDialog:target {
opacity: 1;
pointer-events: auto;
}

.modalDialog > div {
background: -moz-linear-gradient(#FFFFFF, #999999) repeat scroll 0 0 transparent;
border-radius: 10px 10px 10px 10px;
margin: 10% auto;
padding: 5px 20px 13px;
position: relative;
width: 400px;
}

.close {
background: none repeat scroll 0 0 #606061;
border-radius: 12px 12px 12px 12px;
box-shadow: 1px 1px 3px #000000;
color: #FFFFFF;
font-weight: bold;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
text-decoration: none;
top: -10px;
width: 24px;
}

.close:hover {
background: none repeat scroll 0 0 #00D9FF;
}

</style>
</head>
<body>
<a href="#openModal">Click this Link to open up a Model</a>
<div id="openModal" class="modalDialog">
<div>
<a class="close" title="Close" href="#close">X</a>
<h2>Modal Box</h2>
<p>This is a sample modal ...ing the powers of CSS3.</p>
<p>You could do a lot of t...egister form for users.</p>
</div>
</div>
</body>
</html>

莫达尔迪亚洛先生{
-moz转换:不透明度400ms,0秒内缓解;
背景:无重复滚动0 0 rgba(0,0,0,0.8);
底部:0;
字体系列:Arial、Helvetica、无衬线字体;
左:0;
不透明度:0;
指针事件:无;
位置:固定;
右:0;
排名:0;
z指数:99999;
}
.modalDialog:目标{
不透明度:1;
指针事件:自动;
}
.modalDialog>div{
背景:-moz线性渐变(#FFFFFF,#999999)重复滚动0 0透明;
边界半径:10px 10px 10px 10px;
利润率:10%自动;
填充:5px20px13px;
位置:相对位置;
宽度:400px;
}
.结束{
背景:无重复滚动0 0#606061;
边界半径:12px 12px 12px 12px;
盒影:1px 1px 3px#000000;
颜色:#FFFFFF;
字体大小:粗体;
线高:25px;
位置:绝对位置;
右:-12px;
文本对齐:居中;
文字装饰:无;
顶部:-10px;
宽度:24px;
}
.关闭:悬停{
背景:无重复滚动0 0#00D9FF;
}
模态盒
这是一个示例模型…演示CSS3的功能

你可以为用户做很多注册表格


首先
向您添加Id关闭按钮链接

        <a href="#close" title="Close" class="close" id="closeBtn">X</a>

现在使用Javascript

<script type="text/javascript">
      $('#closeBtn').on('click' , function(){
        setTimeout(function() {
        $('#openModal').fadeOut('slow'); }, 10000); 
      });
</script>

$('#closeBtn')。在('click',function()上{
setTimeout(函数(){
$('openModal').fadeOut('slow');},10000;
});
<script type="text/javascript">
      $('#closeBtn').on('click' , function(){
        setTimeout(function() {
        $('#openModal').fadeOut('slow'); }, 10000); 
      });
</script>