在页面完全加载之前出现Javascript强制更改

时间:2017-09-28 16:05:32

标签: javascript browser synchronization

我写了一个由Javascript建模的网站。在网页中,我写了一条消息,以防止用户激活JS。在我的JS代码中,我在第一步删除了这个节点。问题是效果会在页面完全加载之前出现......

var modelerBody = null;

var loadingNode = document.createElement("div");

loadingNode.appendChild(document.createTextNode(messageGeneric['loading']));
loadingNode.setAttribute("id", "loading");

window.onload = function() {

    document.getElementById("jsDisabled").remove()

    var body = document.getElementsByTagName("body")[0];
    body.insertBefore(loadingNode, body.childNodes[0]);
    inflateForms();
    modelerBody = new Modeler.Screen(body.childNodes[1]);
    modelerBody.modelize();
    // Remove Loading message
    body.childNodes[0].remove();

}

我如何解决这个问题? 对不起我的英语我正在学习它......

1 个答案:

答案 0 :(得分:1)

您可以在元素加载之前运行Javascript,方法是将脚本标记放在要删除的div上方,但由于尚未加载div,因此无法找到div。在元素加载之前无法编辑元素。

<?php if (isset($_POST['submit'])) { $id = $_GET["section"]; $about_me = "../include/about_me.php"; $providers_2 = "../include/2providers.php"; $more_providers = "../include/more_proiders.php"; $section_change = $_POST["section_change"]; $query = "UPDATE sections SET "; $query .= "`File Path` = '{$section_change}' "; $query .= "WHERE id = '{$id}' "; $query .= "LIMIT 1"; $result = mysqli_query($link, $query); if ($result && mysqli_affected_rows($link) == 1) { // Success $_SESSION["message"] = "Section Changed."; redirect_to("../index.php?admin=true"); } else { // Failure echo "System Failure. Please try again later. If problem persists please notify your admin at aqeke.com/powerplaylife-help"; } } else { print_r($_POST); } ?> 标记可用于此目的。包装元素以显示用户是否未启用Javascript。

&#13;
&#13;
<noscript>
&#13;
&#13;
&#13;