Cherrypy中的复选框值

2024-09-30 22:15:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道Cherrypy使复选框值可用作listcfg问题(CherryPy - saving checkboxes selection to variables

假设我有以下表单数据:

... snip ...
<input type=checkbox id="1">
<input type=checkbox id="1">
<input type=checkbox id="1">

<input type=checkbox id="2">
<input type=checkbox id="2">
<input type=checkbox id="2">

<input type=checkbox id="3">
<input type=checkbox id="3">
<input type=checkbox id="3">
... snip ...

然后Cherrypy将其作为:

^{pr2}$

从我取消选中第二个复选框id3的那一刻起,我得到:

{'1': [u'on', u'on', u'on'],'2': [u'on', u'on', u'on'],'3': [u'on', u'on']}

有了这个,我无法说出哪个复选框没有被选中。。。。我可以在复选框未选中时使用'off'。。但事实并非如此。在

有什么办法解决这个问题吗?在

干杯

杰伊


Tags: toidinputontypevariablessnip复选框
1条回答
网友
1楼 · 发布于 2024-09-30 22:15:17

首先一点:HTML中的“id”属性对于整个文档来说应该是唯一的。在

然后您有两个选择:

  1. 将“name”属性更改为唯一的,比如<input type="checkbox" name="3b">,在这种情况下,您将返回{..., '3a': u'on' '3c': u'on'},或者
  2. 使这些值唯一,比如<input type="checkbox" name="3" value="b">,在这种情况下,您将得到{..., '3': [u'a', u'c']}。在

相关问题 更多 >