日期:2014-05-17  浏览次数:20723 次

关于JS和CSS结合的一个郁闷问题
在一个页里有一个隐藏的表单项,用CCS   display:none   控制,默认为隐藏的。
并且还用一个checkbox   来控制这个表单是否显示。
当点点击checkbox来让那个表单为   display:block   时

提交。

如果正常提交就没问题了。

可是如果当检测到用户输入的不正确时,就要跳到一个出错页面。出错页里有个按钮
history.back()   用这个返回的。

当再返到第一个页面时,那个隐藏表单就又隐藏了,即回复到默认状态了。

各位大侠有好的办法吗?能让那个表单还显示。

------解决方案--------------------
可以这样做

<script>
function rest()
{
var c = GetCookie( "c ")
if(c == "checked ")
{
document.getElementById( "con ").checked = true
document.getElementById( "x ").style.display = "block "
}
else
{
document.getElementById( "con ").checked = false
document.getElementById( "x ").style.display = "none "
}
}

function SetIt(o)
{
if(o.checked)
{
document.getElementById( "x ").style.display = "block "
SetCookie( "c ", "checked ")
}
else
{
SetCookie( "c ", " ")
document.getElementById( "x ").style.display = "none "
}
}
function SetCookie(sName, sValue)
{
date = new Date(2008,1,1);
document.cookie = sName + "= " + escape(sValue) + "; expires= " + date.toGMTString();
}
function GetCookie(sName)
{

var aCookie = document.cookie.split( "; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split( "= ");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
</SCRIPT>
<body>
<form action= "http://dotnet.aspx.cc/ ">
<input type=checkbox id=con name=con onclick= "SetIt(this) "> 控制
<input type=submit>
<div id= "x " style= "display:none ">
隐藏的内容
</div>
</form>
<script>
rest()
</script>
------解决方案--------------------
禁止缓存
------解决方案--------------------
try
--------------------------------------------
<form name= "form1 " action= "index.htm ">
<input type= "text " name= "t1 "> <input type= "checkbox " name= "c1 " onclick = "show(); "> 显示
<input type= "submit " value= "submit ">
</form>
<script language= "javascript ">
function show(){
document.form1.t1.style.display = document.form1.c1.checked? " ": "none ";
}

window.onload = show;

</script>