[英]How can I make the div reappear again, after the person chose to hide the div? (javascript-related)
So I am javascript illiterate, but I did find this useful code online: 所以我是javascript文盲,但是我在网上确实找到了这个有用的代码:
<script type="text/javascript">
function readCookie( cName )
{
var v;
return decodeURIComponent( ( v = ( document.cookie || "" ).match( "(^|\\s)" + cName + "=([^;$]+)" ) ) ? v[ 2 ] : "" );
}
function setCookie( cName, cValue, life, cPath, cDomain, cSecure )
{
var dt = new Date(),
expSecs = ( expSecs = life.toString().match( /\bsecs\s*=\s*(\d+)/i ) ) ? Number( expSecs[ 1 ] ) : 0,
params = ( life ? ( ";expires=" + new Date( expSecs ? ( dt.setTime( dt.getTime() + expSecs * 1000 ) ) : ( dt.setDate( dt.getDate() + life) ) ).toUTCString() ) : "" )
+ ( cPath ? (";path=" + cPath) : "" )
+ ( cDomain ? ";domain=" + cDomain : "" )
+ ( cSecure ? ";secure" : "" );
document.cookie = cName + "=" + encodeURIComponent( cValue ) + params;
return readCookie( cName );
}
if( readCookie( "close" ) )
{
document.getElementById("thing").style.display="none";
}
function close_thing()
{
document.getElementById("thing").style.display="none";
setCookie( "close", "true", 20 );
}
</script>
It works with this div 它适用于这个div
<div id="thing">
<div id="close_stuff" onclick="close_thing();"><a href="#">Close this</a></div>
</div>
My problem is, if I want my div to contain content, which the user can close if he/she wishes. 我的问题是,如果我希望div包含内容,则用户可以根据需要关闭该内容。 However, I want the div to reappear, when I put new content into the div.
但是,当我在div中添加新内容时,我希望div重新出现。
Is there a way I could do this manually? 有没有办法我可以手动执行此操作? Like rename all the "close_thing" to "klose_thing", or something?
就像将所有“ close_thing”重命名为“ klose_thing”一样?
Thanks! 谢谢!
Adding another function will do this for you. 添加其他功能将为您完成此任务。 Set the display property to block.
将显示属性设置为“阻止”。
function show_thing()
{
document.getElementById("thing").style.display="block";
}
Then call show_thing function display the div again. 然后调用show_thing函数再次显示div。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.