【问题标题】:Hide and show text on button click in asp.net core在 asp.net 核心中单击按钮时隐藏和显示文本
【发布时间】:2020-10-15 13:35:29
【问题描述】:

我正在使用 API 创建一个 Web 应用程序,并使用 HTML 编写了某种帮助页面。 为了清楚起见,我想在按钮单击时隐藏和显示一些文本。

我已经得到了它的 HTML 代码。

<li> GET https://someurl.com/api/getallInformation - some text about data</li>
<div>
    <button onclick="help()">Show Text</button>
</div>
<div id="Text">
    <li>Text that should be shown and hidden on Button click </li>
</div>

但我不知道如何编写 help()-function,使按钮工作。我正在 ASP.NET Core 中编写应用程序。 我知道有很多例子,但我发现的这些例子似乎都不适合我的问题。 知道怎么做吗? Thats what it looks like now. The button just does not work.

【问题讨论】:

  • document.getElementById("element").addEventListener('click', function () { location.href = '@Url.Action("Index","Home")'; }); 在 Url.Action 中可以指定 Controller 名称和 Action 名称。当你点击 Button 时,它会被重定向到“Home”控制器中的“Index”方法。

标签: c# html asp.net-core web-applications


【解决方案1】:

function help() {
  var x = document.getElementById("Text");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
<button onclick="help()">Help</button>

<div id="Text">
<li>Text that should be shown and hidden on Button click </li>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    相关资源
    最近更新 更多