【发布时间】:2019-08-09 14:05:34
【问题描述】:
我这里的东西不起作用。一旦选择美国,它就会摆脱该领域,即使选择其他东西也不会回到选择。
teacher_signup.html
{% block content %}
<h2>Sign Up As Teacher</h2>
<form method="post">
{% csrf_token %}
{% for field in form.visible_fields %}
{{ field | as_crispy_field}}
{% if field.name == "country" %}
<input type="button" value="cube" onclick="getcube()"/>
{% endif %}
{% endfor %}
<button class="btn btn-success" type="submit">Sign Up</button>
</form>
<script>
function getcube(){
var county=document.getElementById("id_country").value;
alert(county);
}
$(document).ready(function() {
$("#id_country").change(function(){
if (this.value=="US"){
$("#id_state").replaceWith();
}
});
});
</script>
{% endblock content %}
forms.py
class TeacherSignUpForm(SignupForm):
country=CountryField(blank_label='(select country)').formfield()
# this is just doing the same thing as country=forms.CharField(max_length=20, widget=forms.Select(choices=COUNTRY_CHOICES), required=True)
state=forms.CharField(max_length=20,required=True)
我想将状态字段替换为 state=forms.CharField(max_length=20, widget=forms.Select(choices=STATE_CHOICES), required=True, strip=True) 如果 country=="US" 并且他们选择了其他内容,那么它将只显示文本字段。
【问题讨论】:
-
您希望这发生在哪里?或者什么时候。在文件加载?什么不工作?有大量代码一目了然。
标签: javascript jquery html django forms