代码之家  ›  专栏  ›  技术社区  ›  Amine

使用js或jquery替换w3 include html attr

  •  1
  • Amine  · 技术社区  · 6 年前

    The w3 schools offers a js script to load html content inside a div using an attribute called w3-load-html. 我试图替换该属性的内容,但JS似乎无法识别它。

    <div id="div" w3-load-html="somecontent.html">
    </div>
    
    $("#div").attr("w3-load-html","someothercontent.html");
    

    以前有人试过这个吗?或者对如何实现它有想法。

    1 回复  |  直到 6 年前
        1
  •  2
  •   CodeF0x    6 年前

    在香草JS中, setAttribute() 可以帮助你:

    var div = document.getElementById('div');
    console.log(div);
    
    // Modify the attribute
    div.setAttribute('w3-load-html', 'someother.html');
    console.log(div);
    <div id="div" w3-load-html="somecontent.html"></div>