在下面的HTML代码中,我有一个包含datetimepicker和数量的表单 动态生成的复选框。如果通过提交按钮提交表单,则所有复选框数据都会按预期传递到后端,但datetimepicker条目不会。对不起,如果这是一个新问题,但我是前端工作的新手。谢谢!
<div class="container">
<div class="row">
<div class="col-md-6">
<h4>Allergic Reaction History</h4>
</div>
<div class="col-md-6">
<h4>Report An Allergic Reaction</h4>
<form action="{{ url_for('reactions') }}" method="post">
<div class="form-group">
<div class="col-md-10" id="dtpicker">
<label class="control-label requiredField" for="datetimepicker1">
Reaction date & time:
<span class="asteriskField">*</span>
</label>
<div class='input-group date form-group' id='datetimepicker1'>
<input type='text' class="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<span class="help-block" id="hint_name">
Click the calendar icon to enter date then click the clock icon to enter time.
Approximations are okay.
</span>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
});
</script>
<label class="control-label requiredField" for="checkbox">
Check all symptoms experienced:
<span class="asteriskField">*</span>
</label>
<div class="checkboxes" id="checkbox-div">
{% for s in symptoms %}
<label class="checkbox-inline no_indent">
<input title="{{ s.desc }}" name="checkbox" type="checkbox" value="{{ s._id }}"/>
{{ s._id }}
</label>
{% endfor %}
<span class="help-block" id="hint_name">
Hover over the checkbox for a symptom to get more details about it.
</span>
</div>
<div>
<button class="btn btn-primary " name="submit" type="submit">
Submit
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
答案 0 :(得分:1)
您需要提供<input>
name
属性,因为只有具有name属性的表单元素在提交表单时才会传递其值。另请参阅https://www.w3.org/TR/html4/interact/forms.html#successful-controls
(请注意,您可以访问复选框值服务器端,但您的复选框 具有name
属性。)