0
我是Django的新手。 現在我已經定義如下如何顯示另一個選擇框,當你從Django的另一個選擇框中選擇
PROPERTY_TYPE_CHOICE = [['1', 'Fixed (TODO)'],
['2', 'Trajectory (TODO)'],
['3', 'Error_Detecting'],
['4', 'Error_Correcting']]
FIXED_TYPE_CHOICE = [['1', 'Prefix',
'2', 'Suffix']]
class UploadFileForm(forms.Form):
# title = forms.CharField(max_length=50)
automata_file = forms.FileField(required = True)
transducer_file = forms.FileField(required = True)
property_type = forms.ChoiceField(choices=PROPERTY_TYPE_CHOICE,
required=True)
fixed_type = forms.ChoiceField(choices=FIXED_TYPE_CHOICE,
required=True)
debug_output = forms.BooleanField(required=False)
我有這個PROPERTY_TYPE_CHOICE在前面HTML
<div class="fieldWrapper">
{{ form.property_type.errors }}
<label for="id_a">Select <u>a type</u> of property:</label>
{{ form.property_type }}
</div>
顯示類,我想展現FIXED_TYPE_CHOICE如果讓我選擇的第一選擇「固定(TODO)」中PROPERTY_TYPE_CHOICE。 我閱讀文檔有關Django的,我認爲它可以通過這種方式來實現:
<div class="fieldWrapper">
{{ form.property_type.errors }}
<label for="id_a">Select <u>a type</u> of property:</label>
{{ form.property_type }}
</div>
{% if form.property_type=='1' %}
<div class="fieldWrapper">
{{ form.fixed_type.errors }}
<label for="id_a">Select <u>a fixed type</u> of property:</label>
{ { form.fixed_type }}
</div>
{% endif %}
但我不能這樣做。 我該怎麼辦?謝謝。
我試過了,但沒有顯示第二個選擇框 – Mike
您是否試圖讓它在您選擇「固定」後立即顯示第二個框?從下拉菜單或頁面刷新後,如果您希望它在不刷新頁面的情況下顯示,則需要使用Javascript。 – cberner
我試圖儘快顯示第二個盒子而不刷新頁面。你知道Javascript的代碼嗎? – Mike