【发布时间】:2018-03-16 22:45:29
【问题描述】:
我已经在一个表单中设置了一个 div,它将显示一个帮助窗口,我想在右上角设置一个“X”,并使用 onclick 功能关闭窗口。这个 div 位于我的 HTML 的底部,就在 end body 标记之前,这是正确的位置吗? 请注意,我想用 display:none 标签来做这个,而不是 show() 或 hide() HTML
<div id="personalhelp"><p class="x"><a href="" onclick="close()">x</a></p>
<p class="help">Your personal information is needed to ensure we provide the most
relevant information and options for you. We will never sell your personal
information to third parties for any reason.</p>
<p class="help">Please fill in all required fields,
these are identified with an asterisk (*)</p>
</div>
函数(jQuery)
function close() {
var getid = $(this).parent.attr('id');
console.log(getid);
$(getid).css("display", "none");
}
CSS
#personalhelp {
position: fixed;
right: 10%;
top: 10%;
max-width: 60%;
display: block;
background-color: #D3D3D3;
color: #000;
margin: 5px auto;
border: 2px solid #000;
display: block;
}
.x {
position: absolute;
right: 1%;
top:1%;
padding: 1px;
margin: 0 auto;
}
.help {
padding: 10px;
}
【问题讨论】:
-
正如我在下面的回答中提到的,将回调名称从
close更改为其他,因为有浏览器原生函数close
标签: javascript jquery html css