【问题标题】:checkbox value not sent to the views in django复选框值未发送到 django 中的视图
【发布时间】:2012-07-19 11:15:41
【问题描述】:

如果复选框被选中,那么只有我看到其他值而不是提交我做错了什么

 <form>
 <input type="checkbox" id="tagdata" name="tagdata" onchange="get_checkbox_value();" value="0"/>
 </form>

function get_checkbox_value()
{
if ($('#tagdata').attr('checked')) {
  $('#tagdata').val('1');
}
else
{
  $('#tagdata').val('0');
}
}

【问题讨论】:

    标签: jquery html django django-views


    【解决方案1】:

    我不确定您要问的确切内容,但仅当复选框被勾选/交叉时才会提交复选框值。如果提交了值,则用户已选中复选框,如果未提交值,则未选中。

    【讨论】:

      【解决方案2】:

      如果我对你的要求是正确的,请使用这个,我很抱歉代码格式。

      <html>
      <head>       <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
      </head>
      </body>
      <form>
       <input type="checkbox" id="tagdata" name="tagdata" onchange="get_checkbox_value();" />
       </form>
      <script>
      function get_checkbox_value()
      {
      if ($('#tagdata').attr('checked')) {
      
         $('#tagdata').val('1');
      
      }
      else
      {
      
      
        $('#tagdata').val('0');
      
      }
      }
      
      </script>
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-09-18
        • 2017-11-04
        • 1970-01-01
        • 1970-01-01
        • 2011-05-26
        • 2021-10-25
        • 2016-07-16
        • 2021-06-28
        相关资源
        最近更新 更多