【问题标题】:Is there a easy way to keep the checked state of radio box in any template system?有没有一种简单的方法可以在任何模板系统中保持单选框的选中状态?
【发布时间】:2012-11-23 12:25:34
【问题描述】:

如果我想在提交表单后保持状态,我真的必须为每个radiocheck box 忍受这个吗?

   <input type="radio" name="all_gene" class="open_gene" checked=
            % if request.GET.get("all_gene") == "0":
                    checked="checked"
            % endif
     value="0"> <label>One gene</label>

    <input type="radio" name="all_gene" class="open_gene" checked=
            % if request.GET.get("all_gene") == "1":
                    checked="checked"
            % endif
     value="1"> <label>Another gene</label>

【问题讨论】:

  • 不是有些浏览器会神奇地记住这些东西吗?无论如何,您可以尝试使用yesno 过滤器而不是{% if %}s,这至少会节省一点空间

标签: python html templates web


【解决方案1】:

您始终可以给出对象和索引的名称,并使用“for”循环来创建它们并使用“get”函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-08
    • 2021-08-19
    • 1970-01-01
    • 2023-01-21
    • 1970-01-01
    • 2011-03-08
    • 2010-09-24
    • 1970-01-01
    相关资源
    最近更新 更多