【问题标题】:window location with the same page(div id)具有相同页面的窗口位置(div id)
【发布时间】:2013-01-19 04:45:06
【问题描述】:

如何使 window.location 转到同一页面但使用另一个不同的 div 标签(或通过 div id 像这样:href="#id")。

    if((mins == 0) && (secs == 0)) {
        window.alert("Time is up.Your score is "+score); // change timeout message as required
        window.location = "index.html" // redirects to specified page once timer ends and ok button is pressed
    } else {
        cd = setTimeout("redo()",1000);
    }

任何帮助将不胜感激。 提前致谢。

【问题讨论】:

  • 您正在寻找location.hash
  • window.location = "/absolute/path/to/page#your-div-id";

标签: javascript html jquery-mobile


【解决方案1】:

您可以在目标元素上使用.scrollIntoView()

document.getElementById("the_div_id").scrollIntoView(true);

【讨论】:

    【解决方案2】:

    只需将哈希添加为字符串:

    window.location + '#id';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      相关资源
      最近更新 更多