Javascript DOM操作问题

Javascript DOM操作问题,javascript,html,css,dom,Javascript,Html,Css,Dom,我希望能够从以下内容创建我的DOM: -标题 -家 -页脚 为此: -标题 -服务 -页脚 以类似SPA的方式,例如仅使用index.html。我有这个代码,不知道为什么它不工作。我在一个月前就做过这件事,那时候很管用。现在我真的不知道为什么当我点击网站导航中的“服务”按钮时,它没有以任何方式更新DOM。有什么想法吗 函数renderHeader(){ 让output=document.getElementById(“output”); 让header=document.createEleme

我希望能够从以下内容创建我的DOM:

-标题 -家 -页脚 为此:

-标题 -服务 -页脚 以类似SPA的方式,例如仅使用index.html。我有这个代码,不知道为什么它不工作。我在一个月前就做过这件事,那时候很管用。现在我真的不知道为什么当我点击网站导航中的“服务”按钮时,它没有以任何方式更新DOM。有什么想法吗

函数renderHeader(){
让output=document.getElementById(“output”);
让header=document.createElement(“header”);
header.innerHTML=`
`; setAttribute(“id”、“header”); 输出.appendChild(头); } 函数renderHome(){ 让output=document.getElementById(“output”); 让needReplace=document.getElementById(“articleID”); 让article=document.createElement(“article”); article.innerHTML=` ➤;Din 2001,城市促销活动este un adevarat sprijin pentru partenerii sai,致力于沃尔塔里品牌urilor 首席执行官卓越,开/关交易渠道利维拉塔,具体接触点 ului品牌。Echipa noastra de lucru Professionista este formata din:225 de angajati全职 (7 birouri teritoriale中的impariti)我是angajati的700名兼职人员。

和#10148;Suntem Capability 在Icelasi timp、avand o baza de resurse Humane complexa、structurata pe Profile中实施二辉橄榄岩项目 必须是项目的五分之一合作伙伴。Putem fata cu brio dezvoltarii项目合作伙伴,包括 colaboram strans cu第三方专门从事创意工作、POSM/展示制作、外包si altele。

`; 条款.setAttribute(“类”、“家庭条款”); 第条.设置属性(“id”、“articleID”); output.replaceChild(article,needReplace); } 函数renderServices(){ 让output=document.getElementById(“output”); 让needReplace=document.getElementById(“articleID”); 让article=document.createElement(“article”); article.innerHTML=` ➤;Suntem专注于德兹沃尔特地区和坎帕尼奥尔地区 在执行中整合ce necesita excelenta、fiind ORTIONE catre rezultate 结论:在lucru cu parteneri de elita,reusind de fiecare data sa integram echipele城市促销业务模式ul ClientColor 诺斯特里。普纳-尼拉-因塞卡!

`; 条款.setAttribute(“类别”、“服务条款”); 第条.设置属性(“id”、“articleID”); output.replaceChild(article,needReplace); } 让currentYear=(新日期()).getFullYear(); 函数renderFooter(){ 让output=document.getElementById(“output”); 让footer=document.createElement(“footer”); footer.innerHTML=`
  • /
  • office@;citypromotions.ro
版权所有©;${currentYear}城市促销活动。

`; setAttribute(“id”,“footer”); output.appendChild(页脚); } 让前面的元素; 功能电流(currentElement){ if(previousElement!=currentElement&&previousElement){ previousElement.classList.remove(“当前”); } currentElement.setAttribute(“类”、“导航当前”); previousElement=currentElement; } 函数start(){ renderHeader(); renderHome(); renderFooter(); } window.addEventListener(“加载”,启动)
原因很简单:必须包含一个
返回falseonclick
处理程序的末尾添加code>,以防止浏览器在执行onclick代码后导航到目标
href

<a href="" class="nav" onclick="current(this); renderServices(); return false;">Servicii</a>
<a href="" class="nav" onclick="current(this); renderPortfolio(); return false;">Portfoliu</a>
...

...

您正在使用链接。用按钮代替。该链接将强制页面刷新