【问题标题】:How do I simultaneously hide a div and redirect to a new HTML page when something is clicked once?单击一次时,如何同时隐藏 div 并重定向到新的 HTML 页面?
【发布时间】:2017-10-15 23:37:19
【问题描述】:

我目前有这个代码

<a href="/#/routeOne" onClick="hide('page1')" class="next">Next &raquo;</a>

应该一键显示一个新页面,One.cshtml 并隐藏 index.cshtml(当前页面)。但是,这需要两次单击才能发生,因为第一次单击显示 One.cshtml 并且不隐藏 index.cshtml,第二次单击隐藏最终隐藏 index.cshtml。

如果有帮助,这里是隐藏功能的代码:

   function hide(obj) {
            var el = document.getElementById(obj);
            el.style.display = 'none';
        }

我也无法理解为什么 index.cshtml 在重定向到 One.cshtml 时不会自动消失。我觉得我一定是做错了什么。

【问题讨论】:

标签: javascript html asp.net-mvc asp.net-mvc-4


【解决方案1】:
<a onClick="hideandgo('page1')" class="next">Next &raquo;</a>

function hideandgo(obj) {
            var el = document.getElementById(obj);
            el.style.display = 'none';
            window.location.href = /#/routeOne;
        }

【讨论】:

  • 不幸的是,即使使用此代码也会出现同样的情况,但感谢您试一试!
  • @bobthebuilder4t5 从锚标签中删除href
猜你喜欢
  • 1970-01-01
  • 2021-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多