如何隐藏或显示DIV基于复选框状态在不同的页面? [英] How to hide or display DIV based on checkbox state on different page?

查看:193
本文介绍了如何隐藏或显示DIV基于复选框状态在不同的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python django 中有一个应用程式,并且有5个部分的摘要网页。让我们称它们为A,B,C,D,E。前三个(A,B,C)是自动生成的,不做任何事情。而最后两个(D,E)是基于复选框状态在完全不同的页面上生成的。

I have an app in python django and there's summary page with 5 sections. Lets call them A, B, C, D, E. The first three (A, B, C) are generated automatically without doing anything. while last two (D, E) are generated based on check-box state on a completely different page.

我试图使用jQuery到目前为止,我已经尝试这一点,但它只有当这些DIV是在同一页上。我尝试谷歌搜索,但找不到任何解决方案。

I am trying to use jQuery to accomplish this so far i have tried this but it only works if those DIV's are on same page. I tried googling but couldn't find any solution.

$(".checkbox").click(function(e){
    var checked = $(this).is(':checked');
    if(checked==true){
        //display those content
    }
});

我甚至不能将其作为 URL参数传递,因为我有一个按钮

I can not even pass it as URL parameter because i have a button on same page as check-boxes which when clicked displays the summary page in pdf format.

FYI:我在页面上使用带有按钮的隐藏的iframe(Well按钮是

FYI: I am using an hidden iframe on the pages with button (Well button is also on four different pages) which have content of summary page and is shown as PDF on button click.

推荐答案

使用简单的cookie

use a cookie easy and nice.

您可以设置一个如下所示的cookie,然后通过javascript

you can set a cookie like the below and then read it through the javascript


设置Cookie:

set cookie:



   document.cookie="checkbox=true";




在下一页读取cookie

read cookie on next page



   var value = readCookie('checkbox');

创建一个允许您每次都返回值的函数

create a function which allows you to get the value back each time

 function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

所以现在当你将它与点击进行比较时,可以这样做:

so now when you compare it with the click you can do something like this:

$(".checkbox").click(function(e){
    var checked = $(this).is(':checked');
    if (checked == undefined || null){
        checked = readCookie('checkbox');
    }
    if(checked==true){
        //display those content
    }
});

这篇关于如何隐藏或显示DIV基于复选框状态在不同的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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