首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复“城市字段不接受值”?

问如何修复“城市字段不接受值”?
EN

Stack Overflow用户
提问于 2020-04-16 14:00:21
回答 1查看 46关注 0票数 1

我正在扩展,自动填写AliExpress航运信息页面上的表单。

我设法填写了除城市字段之外的所有字段的数据。有一个省份字段,它依赖于国家下拉列表和城市字段,如果省份字段有下拉列表,并且用户选择有可用城市的省份,则为城市显示一个下拉列表,否则为城市显示输入,城市的进程也是如此。

现在的问题是,如果城市和省份都输入了,那么它的值就分配给省份,而不是城市,如果我不用js填充省份的值,那么它对城市也没问题。

我尝试了分派事件,在主体中附加脚本,并使用不同的事件,但都不起作用。

注意:有两个隐藏字段的id与省份和城市相同。

代码语言:javascript
复制
if (key == "first_name") {
  $("#contactPerson").focus();
  document.execCommand("insertText", false,
    ae_billing_details[key] + ae_billing_details["last_name"]);
}
if (key == "phone") {
  $("#mobileNo").focus();
  document.execCommand("insertText", false, ae_billing_details[key]);
}
if (key == "address_1") {
  $("#address").focus();
  document.execCommand("insertText", false, ae_billing_details[key]);
}
if (key == "address_2") {
  $("#address2").focus();
  document.execCommand("insertText", false, ae_billing_details[key]);
}
if (key == "state") {
  if ($(".addr-select").has("#province")) {
    $("#province").focus();
    document.execCommand("insertText", false, ae_billing_details[key]);
  }
}
if (key == "postcode") {
  $("#zip").focus();
  document.execCommand("insertText", false, ae_billing_details[key]);
//   var evt = document.createEvent("Events");
//   evt.initEvent("keypress", true, true);
//   evt.view = window;
//   evt.altKey = false;
//   evt.ctrlKey = false;
//   evt.shiftKey = false;
//   evt.metaKey = false;
//   evt.keyCode = 0;
//   evt.charCode = "a";
//   .dispatchEvent(evt);
}
if (key == "city") {
  if ($(".addr-select").has("#city")) {
    $("#city").focus();

    document.execCommand("insertText", false, ae_billing_details[key]);


    $("body").append(
      "<script>document.getElementById('city').value = 'My value';</script>"
    );
    //$( "#city" ).text("gggg");
    //$("#city").attr("value","ok");

    //var element = document.getElementById("#city" );
    // element.parentNode.removeChild(element);
    // var value = $("#city").val();
    // $("#city").focus().val("").val(value);

    //$("#city").val("Mush");
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-04-17 00:32:15

发现并解决了问题。问题出在键的顺序上。这是通过将代码移出for循环来解决的,因为for(obj中的var键)在键序列中提取会导致问题,但在结束时设置状态,因此焦点将转到省,而值不会分配给城市字段。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61243642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档