作爲JavaScript新手,我需要從sessionStorage中檢索數據,並在父輸入刷新後填充父輸入表單以更新某些子記錄。我可以調用函數來刷新頁面和函數以獨立地從sessionStorage獲取數據,但我一直無法合併這些過程,以便a)頁面完全重新加載,然後b)從sessionStorage中檢索數據在頁面重新加載之後。如何做到這一點?如何在頁面刷新後延遲javascript函數執行?
我的頁面刷新(與嘗試要結合使用的setTimeout方法的功能),代碼如下:
<script>
function refreshPage() {
location.reload();
setTimeout(GetSessionData, 4000);
}
</script>
我的函數來獲取數據出來的sessionStorage如下:
<script>
var inputcollection = document.getElementsByTagName("input");
function GetSessionData() {
for (var i = 0; i < inputcollection.length; i++) {
if(document.getElementById(inputcollection[i].name) != null || document.getElementById(inputcollection[i].name) != undefined) {
console.log(i + " " + inputcollection[i].name + "-" + inputcollection [i].value + "-");
if(document.getElementById(inputcollection[i].name).type != "file"){
document.getElementById(inputcollection[i].name).value = sessionStorage.getItem(inputcollection[i].name);
}}}
</script>
人們不能....頁面將重新加載,任何後不會跑步。 – epascarello