html 根据国家下拉字段的选择显示“省”字段的“州”字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 根据国家下拉字段的选择显示“省”字段的“州”字段相关的知识,希望对你有一定的参考价值。

<script>
/*
Unbounce Community :: Tips & Scripts :: Conditional State/ Province Form Field Based on Dropdown 
TS:0002-04-060
***********************
Do not remove this section. It helps our team troubleshoot possible issues and track feature usage and adoption.
*/  
  
  // Conditional Reveal state/province field based on selection of the country dropdown
  // Make sure the "state" field is placed after the country dropdown. Place the province field after the state field
  
(function(){
  var submitBtn = $("#lp-pom-button-65"); // Add ID of Submit Button
  var field = $("#country");  // Add ID of Dropdown field
  
  var conField1 = field.parent().next();
  var conField2 = conField1.next();
  
  var topPos = conField1.position().top;
  conField2.css({top: topPos});        
  
  conField1.css("display", "none");
  conField2.css("display", "none");
  
  var fieldHeight = conField1.height();
  var space = fieldHeight*2+37;
  var halfSpace = space/2;
  
  var moreFields = $(conField2).nextAll();
  moreFields.animate({top: "-=" + space},0); 
  var i = true;
  $(field).change(function() {
    if ($(this).val() == "United States") {
      conField1.fadeIn("slow");
      conField2.fadeOut("slow");
      if (i) {
        fieldAdjust();
        i = false;
      }
    } else if ($(this).val() == "Canada") {
      conField1.fadeOut("slow");        
      conField2.fadeIn("slow");
      if (i) {
        fieldAdjust();
        i = false;
      }
    } else {
      i = true;
      conField1.fadeOut("slow");
      conField2.fadeOut("slow");
      if (conField1.css('display') == 'block' || conField2.css('display') == 'block') { 
        moreFields.animate({top: "-=" + halfSpace}, 600);
        submitBtn.animate({top: "-=" + halfSpace}, 600);
      }  
    }
  });
  var fieldAdjust = function() {
    moreFields.animate({top: "+=" + halfSpace}, 600);
    submitBtn.animate({top: "+=" + halfSpace}, 600);
  }
})();  
</script>

以上是关于html 根据国家下拉字段的选择显示“省”字段的“州”字段的主要内容,如果未能解决你的问题,请参考以下文章

如何在颤动中选择基于下拉项添加文本字段值

Vuejs 根据从下拉列表中选择的值显示其他输入字段

通过 ip 获取用户国家并将其显示在下拉列表顶部,但不预先选择它

根据下拉选择动态填充字段(Javascript / HTML)

根据下拉列表中的选定值显示表单字段Angular TypeScript

用js或者jq实现,根据下拉菜单的字段来显示对应的内容?