Javascript jQuery post()的显示/隐藏功能

Javascript jQuery post()的显示/隐藏功能,javascript,jquery,Javascript,Jquery,我通过使用jQuery post()方法的Javascript函数调用Python脚本,如下所示 function onChangeTitularInfraestructura(val) { if (val=='10') { $.post("/folder_1/pyscript/getSelectTitularInfraestructura", {name:'f_titular_infraestructura',value:val, all

我通过使用jQuery post()方法的Javascript函数调用Python脚本,如下所示

function onChangeTitularInfraestructura(val) {
            if (val=='10') {
                $.post("/folder_1/pyscript/getSelectTitularInfraestructura", {name:'f_titular_infraestructura',value:val, all:'',styleclass:'form-element',empty:'True' }, function(data) {
                    $('#div_titular_infraestructura').html( data );
                }).fail( function(){ $( "#div_titular_infraestructura" ).html( "Internal Server Error" ); } );

                $('#div_titular_infraestructura').show();
            } else {
                $("#div_titular_infraestructura").hide();
            };
        };
它按预期工作,也就是说:如果我点击调用onChange的下拉列表的值(10),就会出现另一个下拉列表(由python脚本构建);否则,将隐藏div

不过,我有一个问题:如果我不使用
show()
方法写这行代码,它将无法按预期工作。如果我在第一次单击时选择值10,它会出现,如果我选择其他值,它会消失(到目前为止还可以),但如果我再次选择值10,它不会再次出现,它会保持隐藏状态


解释是什么?

最初您的div
div\u titular\u infrastructure
不包含任何值,因此它似乎是隐藏的。当您第一次选择10时,该值将填充到该div中,并显示为可见

当您选择其他值时,它会隐藏div,将其显示样式设置为,因此当您选择值10而不选择
显示()
方法时,此属性(显示)不会得到切换,并且保持隐藏状态

使用
show()
方法
display
设置为
,并在屏幕上显示