Javascript innerHTML命令中存在大量HTML代码的问题
我目前正在一个名为GeneralJS的JS文件中编写一个简单的JS函数 它应该执行一个滑块。函数如下所示Javascript innerHTML命令中存在大量HTML代码的问题,javascript,html,Javascript,Html,我目前正在一个名为GeneralJS的JS文件中编写一个简单的JS函数 它应该执行一个滑块。函数如下所示 function LoadSideBar() { document.getElementById("sideBarDiv").innerHTML = "<div data-role="panel" data-position="left" data-position-fixed="false" data-display="reveal" id="nav-panel" data-them
function LoadSideBar() { document.getElementById("sideBarDiv").innerHTML = "<div data-role="panel" data-position="left" data-position-fixed="false" data-display="reveal" id="nav-panel" data-theme="a">
<a href="index.html" data-role="button" data-theme="e" data-icon="home" > 1</a><br/>
<a href="NewTask.html" data-role="button" data-theme="b" data-icon="plus" > 2</a><br/>
<a href="JoinGroups.html" data-role="button" data-theme="b" data-icon="search" > 3</a><br/>
<a href="Groups.html" data-role="button" data-theme="b" data-icon="grid" > 4</a><br/>
<a href="Settings.html" data-role="button" data-theme="b" data-icon="gear" > 5</a><br/>
<a href="" data-role="button" data-theme="b" data-icon="info" > 6 </a><br/>
<a href="" data-role="button" data-theme="b" data-icon="arrow-r" > 7 Us </a><br/>
<a href="" data-role="button" data-theme="b" data-icon="minus" > 8 </a>
</div>";
}
函数LoadSideBar(){document.getElementById(“sideBarDiv”).innerHTML=”
";
}
HTML执行代码是
LoadSideBar()
问题似乎是在.innerHTML=之后,我在引号中放了很多HTML代码,因为当我将HTML代码更改为
“Hi”
时,一切都正常。有人有线索吗 问题是您正在定义这个长字符串,该字符串用双引号(“
)括起来,它也在您试图放入字符串的html代码中,因此该字符串在html代码的第一个引号后停止。通过使用单引号(”
)定义字符串,可以很容易地解决这个问题因为html代码不使用它们:
function LoadSideBar() { document.getElementById("sideBarDiv").innerHTML = '<div data-role="panel" data-position="left" data-position-fixed="false" data-display="reveal" id="nav-panel" data-theme="a"> <a href="index.html" data-role="button" data-theme="e" data-icon="home" > 1</a><br/> <a href="NewTask.html" data-role="button" data-theme="b" data-icon="plus" > 2</a><br/> <a href="JoinGroups.html" data-role="button" data-theme="b" data-icon="search" > 3</a><br/> <a href="Groups.html" data-role="button" data-theme="b" data-icon="grid" > 4</a><br/> <a href="Settings.html" data-role="button" data-theme="b" data-icon="gear" > 5</a><br/> <a href="" data-role="button" data-theme="b" data-icon="info" > 6 </a><br/> <a href="" data-role="button" data-theme="b" data-icon="arrow-r" > 7 Us </a><br/> <a href="" data-role="button" data-theme="b" data-icon="minus" > 8 </a> </div>'; }
function LoadSideBar(){document.getElementById(“sideBarDiv”).innerHTML='
;}
检查控制台…您没有正确使用引号。。。