简体   繁体   English

在短时间内显示隐藏的div,具体取决于url中的PHP $ GET

[英]Show hidden div for short period of time depending on PHP $GET in url

I have two different hidden divs. 我有两个不同的隐藏div。 They are hidden with css "display:none;". 它们隐藏着css“display:none;”。 Both of the divs contains a single image. 两个div都包含一个图像。 Upon page load I would like div 1 to be shown for a short period of time if the url is "www.myserver.com/index.php?succeded=yes" and div 2 to be shown instead if the url says "www.myserver.com/index.php?succeded=no". 在页面加载时,如果网址为“www.myserver.com/index.php?succeded=yes”,则我希望div 1显示一段时间,如果网址显示为“www”,则显示div 2。 myserver.com/index.php?succeded=no”。

Can this be done with jquery? 这可以用jquery完成吗?

To read "succeded": Get escaped URL parameter . 阅读“已成功”: 获取转义的URL参数

Using the function function getURLParameter(name) : 使用函数function getURLParameter(name)

if (getURLParameter('succeded') == 'yes') {
    $('#mydiv').show();
    window.setTimeout(function () { $('#mydiv').hide(); }, 5000); // hide after 5s
}

that should do the trick. 这应该够了吧。

You can use .split() method of jQuery: 你可以使用jQuery的.split()方法:

var url = "www.myserver.com/index.php?succeded=yes"; // window.location.href;
var str = url.split('?')[1];

if(str == "succeded=yes"){
    $('.yesdiv').show().delay(2000).hide();
}else{
    $('.nodiv').show().delay(2000).hide();
}

First of all, parameters in the URL are GET parameters, not POST. 首先,URL中的参数是GET参数,而不是POST。

And of course this can be done – either you already check for this parameter server-side and then just output the appropriate JS code; 当然,这可以做到 - 要么你已经检查了这个参数服务器端,然后只输出适当的JS代码; or you check the URL of the current document in JS yourself, using location.search to access the query string part of the URL. 或者您自己检查JS中当前文档的URL,使用location.search访问URL的查询字符串部分。

我认为如果你将php变量解析为js会更容易

var any = "<?=isset($_GET['success'])?$_GET['success']:''?>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM