Django crispy形式的条件逻辑
我有一个表单,我想知道我应该如何隐藏字段“conditionalWeb”,直到用户选择“Web应用程序”作为项目字段的类型 我已经在网上做了研究,但我完全不知道如何继续。。。任何帮助都很好:)Django crispy形式的条件逻辑,django,forms,django-crispy-forms,Django,Forms,Django Crispy Forms,我有一个表单,我想知道我应该如何隐藏字段“conditionalWeb”,直到用户选择“Web应用程序”作为项目字段的类型 我已经在网上做了研究,但我完全不知道如何继续。。。任何帮助都很好:) 谢谢:)您可以为任务添加一个简单的javascript: $(document).ready(function(){ hideShow() }) // call hideShow when the user clicks on the project_type dropdownlist $('#
谢谢:)您可以为任务添加一个简单的javascript:
$(document).ready(function(){
hideShow()
})
// call hideShow when the user clicks on the project_type dropdownlist
$('#id_typeoftheproject').click(function(){
hideShow()
});
function hideShow(){
if(document.getElementById('id_typeoftheproject').value == "7")
{
$('#id_conditionalweb').show();
}
else
{
$('#id_conditionalweb').hide();
}
}
您需要从数据库中找到字段的实际id,并替换项目的#id_typeofproject和#id_conditionalweb。此外,值“7”需要替换为web应用程序的id
$(document).ready(function(){
hideShow()
})
// call hideShow when the user clicks on the project_type dropdownlist
$('#id_typeoftheproject').click(function(){
hideShow()
});
function hideShow(){
if(document.getElementById('id_typeoftheproject').value == "7")
{
$('#id_conditionalweb').show();
}
else
{
$('#id_conditionalweb').hide();
}
}