根据查询字符串值显示/隐藏元素 [英] Show / Hide elements based on query string value

查看:90
本文介绍了根据查询字符串值显示/隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在页面上有一些div元素,我默认情况下需要隐藏这些元素,直到提交表单并将用户重定向回同一页面,例如,将查询字符串附加到url(?success = true)上.

Have some div elements on a page that I need to hide by default until a form is submitted and the user redirected back to the same page with a query string appended to the url (?success=true) for example.

有人可以在这里帮助吗?

Can anyone help here?

推荐答案

$(document).ready(function () {
  $("div.show_on_success").toggle(document.URL.indexOf("success=true") !== -1);
});

如果页面的URL中出现"success = true",则此代码显示类为show_on_success的div,否则将其隐藏.

This code shows the divs with class show_on_success if "success=true" appears in the page's URL, and hides them otherwise.

这篇关于根据查询字符串值显示/隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆