2

我有一个输入表单,它接受报告的参数。我将这些提交到同一页面。生成报告后,我想将用户移动到报告的顶部。但是,javascript 不会成为锚点。当我的 href 是不同但其他方面相同的页面时,锚点起作用,但当它是同一页面时,它不会。例子:

<script type="text/javascript">
function moveto() {
window.location.href = "frag6.cfm#betty";
}
</script>
</head>
<body>
<script type = "text/javascript">
moveto()
</script>
<cfset subtest = ArrayNew(1)>
<cfloop from = "1" to = "10" index = "m">
<cfloop from = "1" to = "3" index = "i">
<cfloop from = "1" to = "4" index = "j">
<cfset test[i][j] = "#m#_#i#_#j#">
</cfloop>
</cfloop>
</cfloop>

<cfdump var = "#test#">
<cfloop from = "1" to = "3" index = "i">
<cfloop from = "1" to = "4" index = "j">
<cfset subtest[j] = test[i][j]>
</cfloop>

<cfdump var = "#subtest#">
</cfloop>
<a name = "betty"> here I am </a>
4

1 回答 1

1

您应该为锚点使用id属性而不是 name 和location.hash而不是 location.href

<div id="happyanchor"></div>

<script>
function goToAnchor(anchor){
    location.hash = anchor;
}

goToAnchor('happyanchor');
</script>
于 2013-04-12T18:31:54.910 回答