我目前正在从事涉及Flask-wtforms模块制作的登录表单的Flask初学者Web项目:
class LogInForm(FlaskForm):
username = str_field('Username', validators=[DataRequired(), Length(min=2, max=20)])
email = str_field('Email', validators=[DataRequired(), Email()])
password = pwd_field('Password', validators=[DataRequired(), Length(min=6, max=20)])
remember = BooleanField('Remember Me')
submit = smt_field('Log In')
这是我的HTML中的表单片段:
<form action="" method="post">
{{ form.hidden_tag() }}
<fieldset class="form-group">
<legend> Log In </legend>
<div class="form-group">
{{ form.username(class="form-control form-control-md", placeholder="Username", autocomplete="off") }}
</div>
<div class="form-group">
{{ form.password(class="form-control form-control-md", placeholder="Password") }}
</div>
<div class="form-check mb-3">
{{ form.remember(class="form-check-input") }}
{{ form.remember.label(class="form-check-label") }}
</div>
<button class="btn btn-outline-primary" type="submit">Log In</button>
</fieldset>
</form>
<button type="button" class="btn btn-info btn-small mt-4">Use Email for Log In</button></small>
我要使最后一个按钮将form.username字段更改为form.email字段,以便用户可以在两者之间进行选择。我怎样才能做到这一点? jQuery是必需的吗?