function submitForm(){
let form = document.getElementById("autoForm");
form.submit();
}
window.onload = function () {
let selE = document.createElement("select");
selE.name = "selectedCmd";
let lis = ["aaa","bbb"];
for (let i=0;i<lis.length;i++) {
let op = new Option(lis[i],lis[i]);
selE.options.add(op);
}
let formE = document.createElement("form");
formE.id = "autoForm";
formE.action = "/ax";
formE.method = "GET";
formE.appendChild(selE);
// selE.onchange = formE.submit; //*** 不行,执行报错
selE.onchange = submitForm; //这样才行
let divF = document.getElementById("divF");
divF.appendChild(formE);
}
1
9yu 2020-04-13 09:08:03 +08:00 1
```js
selE.onchange = () => { form = document.getElementById("autoForm").submit() } ``` |
2
otakustay 2020-04-13 09:08:17 +08:00 2
因为 submit 需要 this
|
3
ismumu 2020-04-13 09:44:10 +08:00 1
selE.onchange = () => {
formE.submit(); } |