简体   繁体   English

单击时显示/隐藏 W3.JS HTML 包含

[英]Show/Hide W3.JS HTML Includes on click

I have this code:我有这个代码:

<ul>
    <li>
        <a href="#" id="fiatClick">Fiat</a>
    </li>
    <li>
        <a href="#" id="audiClick">Audi</a>
    </li>
</ul>

<div id="showCarInfo"></div>

And when a link is clicked, the proper content related to that link should be appended inside id="showCarInfo" .当一个链接被点击时,与该链接相关的正确内容应该被附加到id="showCarInfo" 中

As of now, with each click a new set of content is being generated instead of the content being swapped.截至目前,每次点击都会生成一组新的内容,而不是交换内容。 How do I replace (toggle) the content inside the div with each click?每次单击如何替换(切换)div 内的内容? I am using W3.JS to include HTML files in my HTML and this is my JS:我正在使用 W3.JS 在我的 HTML 中包含 HTML 文件,这是我的 JS:

$('#fiatClick').click(function(e) {
        e.preventDefault();
        $('#showCarInfo').append('<div w3-include-html="fiat.html"></div>');
        w3.includeHTML();
    });
    $('#audiClick').click(function(e) {
        e.preventDefault();
        $('#showCarInfo').append('<div w3-include-html="audi.html"></div>').show();
        w3.includeHTML();
    });

你能把 .append() 改成 .html() 吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM