【问题标题】:Node Formidable Radio Buttons节点强大的单选按钮
【发布时间】:2018-05-11 20:53:59
【问题描述】:

我正在努力确定在 Node.js 中使用 formidable 勾选了哪个单选按钮。这是我的表格:

<form action="/upload" enctype="multipart/form-data" method="post">
   <div class="form-group text-center">
     <div class="radio">
       <label>
         <input type="radio" name="clean" checked="checked">Clean</label>
     </div>
     <div class="radio">
       <label>
         <input type="radio" name="clean">Waste</label>
     </div>
     <input class="form-control" type="file" name="file" accept=".xlsx">
     <input class="form-control btn btn-primary" type="submit" value="Upload">
   </div>
 </form>

当我使用form.parse(req, (err, fields, files) =&gt; {} 解析时,字段仅包含{"clean":"on"},无论在发布时选中哪个单选按钮。

【问题讨论】:

    标签: javascript html node.js express formidable


    【解决方案1】:

    您必须在单选按钮中使用value 属性,例如:

    <input type="radio" name="clean" value="clean" checked>
    <input type="radio" name="clean" value="waste">
    

    如果没有指定value 属性,则默认为"on",这正是您所观察到的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      相关资源
      最近更新 更多