Javascript 在get或post之后更改div显示
我有几张唱片。其中之一是:Javascript 在get或post之后更改div显示,javascript,html,Javascript,Html,我有几张唱片。其中之一是: <div id="content1" style="display:none;"> 正如上面的代码,我想在获取“ownerid”之后显示“content1”,然后将display设置为“initial”。但它不起作用。有什么方法可以实现我的想法吗?谢谢 编辑: 由于重新加载页面,javascript更改不会持续。您必须在页面加载本身上检查ownerid: var ownerid = location.search.match(/ownerid=(
<div id="content1" style="display:none;">
正如上面的代码,我想在获取“ownerid”之后显示“content1”,然后将display设置为“initial”。但它不起作用。有什么方法可以实现我的想法吗?谢谢 编辑:
由于重新加载页面,javascript更改不会持续。您必须在页面加载本身上检查ownerid:
var ownerid = location.search.match(/ownerid=(\w+)/);
if(ownerid && ownerid[1]) {
document.getElementById("content1").style.display="initial";
}
在这里,
location.search
将为您提供查询字符串,即?ownerid=value
。下一个match(/ownerid=(\w+/)
将给出一个ownerid参数数组及其值[“ownerid=value”,“value”]
,如果缺少参数,它将为空。如果您没有使用
的正确id,请尝试以下操作:
document.getElementById("div1").style.display="initial";
重新加载页面后,div可见性的变化不会改变。如果设置了ownerid
参数,则可以在加载页面时进行检查,并使用该参数确定div的可见性。我的错误,div id应该是“content1”。但它不工作,因为重新加载页面,我认为.div id应该是“content1”,我在我的问题中更改了它。问题是window.location将续订页面。。。。。。
document.getElementById("div1").style.display="initial";