douxiong3245 2014-02-28 07:33
浏览 39
已采纳

javascript中的“页面顶部”链接

Using php in a webpage and struggled with anchoring to the top, so I'm using a line of javascript to accomplish what I want. The code is:

<script language="JavaScript" type="text/javascript">
<!--
document.write("<a href= \"" + document.location + "#top\" >Top of Page</a>");
// -->
</script>

Only problem is, I want to take the code and add a:

class="bmenu"

line to it so it will be formatted the same as other links (color, font, etc.). I know nothing of javascript, so this is probably a simple thing, but would be a really helpful workaround for those who need to link to the top of a page, but have limitations as to which method they can use.

Thanks in advance!

Here's what the code looks like for those curious.

I have a .php file titled bmenu.php that contains a bottom menu that is added to every page. It contains

|&emsp;
<a href="index.php" class="bmenu">Home</a>
&emsp;|&emsp;
<a href="about_us.php" class="bmenu">About Us</a>
&emsp;|&emsp;
<a href="find_us.php" class="bmenu">Find Us</a>
&emsp;|&emsp;
<a href="contact_us.php" class="bmenu">Contact Us</a>
&emsp;|&emsp;
<script language="JavaScript" type="text/javascript">
<!--
document.write("<a class=\"bmenu\" href= \"" + document.location + "#top\" >Top of Page</a>");
// -->
</script>
&emsp;|

and then in each file that I want this menu I add

<?php include 'PHP/bmenu.php'; ?>

This saves typing and enables me to make a single edit to the menu rather than editing every page that I want that menu on every time I want to change it.

  • 写回答

2条回答 默认 最新

  • duanpang1987 2014-02-28 07:36
    关注

    Try this:

    document.write("<a class=\"bmenu\" href= \"" + document.location + "#top\" >Top of Page</a>");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3