我正在扩展,自动填写AliExpress航运信息页面上的表单。
我设法填写了除城市字段之外的所有字段的数据。有一个省份字段,它依赖于国家下拉列表和城市字段,如果省份字段有下拉列表,并且用户选择有可用城市的省份,则为城市显示一个下拉列表,否则为城市显示输入,城市的进程也是如此。
现在的问题是,如果城市和省份都输入了,那么它的值就分配给省份,而不是城市,如果我不用js填充省份的值,那么它对城市也没问题。
我尝试了分派事件,在主体中附加脚本,并使用不同的事件,但都不起作用。
注意:有两个隐藏字段的id与省份和城市相同。
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");
}
}发布于 2020-04-17 00:32:15
发现并解决了问题。问题出在键的顺序上。这是通过将代码移出for循环来解决的,因为for(obj中的var键)在键序列中提取会导致问题,但在结束时设置状态,因此焦点将转到省,而值不会分配给城市字段。
https://stackoverflow.com/questions/61243642
复制相似问题