Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未处理的承诺拒绝:TypeError:null不是对象(正在评估';editUserUI.innerHTML=interfaceHTML';)_Javascript_Html_Null_Innerhtml_Getelementbyid - Fatal编程技术网

Javascript 未处理的承诺拒绝:TypeError:null不是对象(正在评估';editUserUI.innerHTML=interfaceHTML';)

Javascript 未处理的承诺拒绝:TypeError:null不是对象(正在评估';editUserUI.innerHTML=interfaceHTML';),javascript,html,null,innerhtml,getelementbyid,Javascript,Html,Null,Innerhtml,Getelementbyid,我试图在javascript中设置id为“admin edit user content”的div元素的内部html。但是控制台在互动程序中给出了错误,显然是我的document.getElementById(“#admin edit user content”)为空。然而,这个元素确实存在。它位于我的index.html的正文中: <html lang="nl"> <head> <meta charset="UTF-8&quo

我试图在javascript中设置id为“admin edit user content”的div元素的内部html。但是控制台在互动程序中给出了错误,显然是我的
document.getElementById(“#admin edit user content”)为空。然而,这个元素确实存在。它位于我的index.html的正文中:

<html lang="nl">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- Compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> 
</head>
<body class="grey lighten-3">
    <!-- There's a lot of other code here that is not relevant right now -->
    
    <div id="modal-admin-edit-user" class="modal">
      <div class="modal-content">
        <h4>Gebruiker bewerken</h4>
        <div id="admin-edit-user-content">
          <!-- inner html goes here -->
        </div>
      </div>
    </div>

    <!-- Some more code  -->

    <script src="/scripts/index.js"></scripts>
</body>
</html>
提前谢谢大家,, Jonas

如果您正在使用,则在ID之前不需要
#
。只需这样做即可

document.getElementById('admin-edit-user-content');
如果正在使用或,则使用

如果正在使用,则在ID之前不需要
。只需这样做即可

document.getElementById('admin-edit-user-content');

如果使用or,则使用

缺少一些代码,因此我无法预测太多。 选中此项:

  • document.getElementById(“管理员编辑用户内容”)//不需要
  • 希望这有助于:

    
    格布鲁伊克·比沃肯
    你的钮扣
    函数updateEditUserUI(){
    //editUserUI为空,我不明白为什么
    const editUserUI=document.getElementById(“管理员编辑用户内容”);
    const interface html=“一些内部html

    ”; //在这里我得到了一个例外: editUserUI.innerHTML=interfaceHTML; };
    有一些代码缺失,因此我无法预测太多。
    选中此项:

  • document.getElementById(“管理员编辑用户内容”)//不需要
  • 希望这有助于:

    
    格布鲁伊克·比沃肯
    你的钮扣
    函数updateEditUserUI(){
    //editUserUI为空,我不明白为什么
    const editUserUI=document.getElementById(“管理员编辑用户内容”);
    const interface html=“一些内部html

    ”; //在这里我得到了一个例外: editUserUI.innerHTML=interfaceHTML; };
    谢谢!还在学习html,我把2搞错了。谢谢!还在学习html,我把2搞混了。
    // A lot of code goes before this 
    
    // this function is called on a button press
    function updateEditUserUI(uid) {
      // editUserUI is null and I don't understand why
      const editUserUI = document.getElementById("#admin-edit-user-content");
      
      const interfaceHTML = `
        <p>Some inner html, I've gotten rid of all the details because they are not relevant for this question</p>
      `;
        
      // Right here I get the exception:
      editUserUI.innerHTML = interfaceHTML;
    }
    
    // more code
    
    var cont = false;
    document.addEventListener('DOMContentLoaded',() => {
        cont = true;
    });