我怎樣才能在同一個 if 中執行所有操作?目前只執行最后一個
if (test==1) {
document.getElementById("opciones").action='1ExcelArchivos.php';
document.getElementById("opciones").submit();
document.getElementById("opciones").action='2ExcelArchivos.php';
document.getElementById("opciones").submit();
document.getElementById("opciones").action='3ExcelArchivos.php';
document.getElementById("opciones").submit();
document.getElementById("opciones").action='4ExcelArchivos.php';
document.getElementById("opciones").submit();
}
uj5u.com熱心網友回復:
這在一定程度上取決于 PHP 端點正在做什么,但最終可以對這些檔案進行分組。
例子:
ExcelArchivos.php:
<?php
require __DIR__ . '/1ExcelArchivos.php';
require __DIR__ . '/2ExcelArchivos.php';
require __DIR__ . '/3ExcelArchivos.php';
require __DIR__ . '/4ExcelArchivos.php';
if (test==1) {
document.getElementById("opciones").action='ExcelArchivos.php';
document.getElementById("opciones").submit();
}
無論 PHP 示例是直接擬合還是需要不同的方法,如果在一天結束時您只有一個端點而不是四個端點,您可以通過一次提交來處理它。
瀏覽器通常一次只能處理一個 submit() 操作,因為它與導航相關,并且只有一種導航方式。這也是為什么最后一個 submit() 確實取代了早期的原因。
uj5u.com熱心網友回復:
您可以嘗試通過 XMLHttpRequest 發送
if (test == 1) {
var f = document.getElementById("opciones");
var postData = [];
for (var i = 0; i < f.elements.length; i ) {
postData.push(f.elements[i].name "=" f.elements[i].value);
}
var to = ['1ExcelArchivos.php', '2ExcelArchivos.php', '3ExcelArchivos.php', '4ExcelArchivos.php'];
for (var i = 0; i < to.length; i ) {
var xhr = new XMLHttpRequest();
xhr.open("POST", to[i], true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(postData.join("&"));
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/341319.html
標籤:javascript
下一篇:訪問輸入欄位Puppetier
