【问题标题】:Why not working innerHTML + include-html?为什么不工作 innerHTML + include-html?
【发布时间】:2020-08-30 13:55:54
【问题描述】:

对不起,我的英语不好。但我想解决这个问题。 这是html代码。

 <body>
<div id="booklist">
    <?php include("../templates/nav.php"); ?>
    <div class="hero">
        <?php include("../templates/aside.php"); ?>
        <main>
        </main>
    </div>
    <?php include("../templates/footer.php"); ?>
</div>
<script src="../dist/bookList_bundle.js"></script>

这是 js 代码。 addEventListener 在旁边工作。

import {includeHTML} from "../js/includeHTML";
includeHTML();

document.querySelectorAll('.link').forEach(item => {
item.addEventListener('click', (event) => {
  aside.clickLi(item.textContent);
})

includeHTML 是https://www.w3schools.com/howto/howto_html_include.asp 的脚本 它正在使用 webpack 处理另一个文件。

而且是课外。

class aside{
  clickLi(data){
    const main = document.querySelector("main");

    let sectionName = data;
    main.innerHTML= `<section include-html="./section/${sectionName}.php" class="section"></section>`;
  }
}

我想在主标签中使用包含 html 源代码。 但它不起作用..

我想加载这个 html 源代码。

<div>
This is one of sectioNname.
</div>

【问题讨论】:

    标签: javascript php html include


    【解决方案1】:

    尝试在 clickLi 函数之前添加静态,如下所示: static clickLi(

    【讨论】:

    • 感谢您的回答。但是,它无法读取您所说的“clickLi”。
    猜你喜欢
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2014-10-15
    • 2014-03-11
    • 1970-01-01
    相关资源
    最近更新 更多