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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答