jQuery中的函数调用

function calling in jquery

本文关键字:函数调用 jQuery      更新时间:2023-09-26

我想显示div 的 id是 deliveryto1,如果条件为真,则不显示 deliverto1div。这个div(#deliverto1)总是显示在其他部分。

 $('#delivery').change(function () {
    if ($(this).val() == 1) {
      $('#deliverto1').show();  
      $('#deliverto').hide();
    } else {
          $('#areas').show()
          $('#deliverto').show();
    }
});

您忘了在 else 部分中隐藏div。 在 else 部分中使用 .hide(),如下所示

$('#delivery').change(function () {
    if ($(this).val() == 1) {
      $('#deliverto1').show();  
      $('#deliverto').hide();
    } else {
          $('#areas').show()
          $('#deliverto').show();
          $('#deliverto1').hide(); 
    }
});