【问题标题】:webpy radio buttons网页单选按钮
【发布时间】:2012-08-07 19:58:26
【问题描述】:

我正在使用 webpy 创建一个网页,我需要使用单选按钮来执行一些条件,我找不到任何关于此的文档,只是想知道如何使用 fow 控件,例如:if radio1.checked() : do stuff

任何帮助都会很棒我是 dweb 编程新手

【问题讨论】:

    标签: radio-button web.py


    【解决方案1】:

    你会这样做:

    radio_button = form.Form( 
        form.Radio('details', ['option1', 'option2', 'option3', 'option4']),
        )
    

    此外,您可以让 webpy 呈现一个 html 页面并将单选按钮 html 标记放入该页面。如果您是编程新手,我建议您不要尝试学习如何使用 webpy 的模板系统。对于初学者来说太抽象了。而是使用 webpy 为您的页面提供服务并定期编写您的页面。然后当你觉得舒服时,你应该考虑一个不错的独立模板引擎,比如 Jinja2。

    这里也有回答:

    How to use radio buttons in python web.py

    【讨论】:

      【解决方案2】:

      我很确定 Paxwell 误读了您想要做的事情。我有我的单选按钮通过 ajax 在一个大表单内发送。

      html 是这样的

      <form> 
          ... form stuff...
          <div class="control-group">         
            <div class="controls">    
               <label class="radio">
                <input type="radio" name="radioId" value="option1" checked>
                     Reporter 1
                </label>
               <label class="radio">
                 <input type="radio"  name="radioId" value="option2" 
                    Reporter 2
               </label>  
              ..
              </div>
           </div>
       </form>
      

      我的 main.py:

      def POST(self):
      form = web.input()
      

      经过试验,单选按钮将在表单内部!我用同名命名了我的单选按钮。当您选择: form.radio_id,它只会返回选中的值。在这种情况下你会得到option1

      radiobutton= "%s" % (form.radioId)
      if radiobutton == "option1":
          print "hooray!"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-08
        • 1970-01-01
        • 2014-02-08
        • 2021-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多