【发布时间】:2021-12-02 02:28:30
【问题描述】:
在我的 Asp MVC 程序中,我可以使用按钮切换 div。 cshtml:
<button onclick="ShowPubs()"> Click to show or hide</button>
JScipt:
函数 ShowPubs() {
var x = document.getElementById("myPubs");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
这很好用,
但是,当尝试使用此代码中的链接时: cshtnl:
<div id="AboutShow" style="display:block">
Show the hidden piece <a href="#" onclick="ShowAbout();">Show ▼</a>
</div>
<div id="AboutHide" style="display:none">
Hide these details <a href="#" onclick="ShowAbout();">Hide ▲</a>
A lot more stuff
</div>
使用此 JavaScript:
函数 ShowAbout() {
var x = document.getElementById("AboutShow");
var y = document.getElementsById("AbourHide");
if (x.style.display === "none") {
x.style.display = "block";
y.style.display = "none";
} else {
x.style.display = "none";
y.style.display = "b;pck";
}
return false;
}
页面 url 将 # 添加到 url 并且没有其他任何事情发生,请问我在这里做错了什么?
【问题讨论】:
标签: javascript html asp.net-core razor