2013-04-01 29 views
2

我有一个输入窗体,它接收报表的参数。我将这些提交到相同的页面。生成报告时,我想将用户移到报告的顶部。但是,JavaScript不会成为主播。当我的href是一个不同但其他方面相同的页面时,锚点工作,但是当它是同一页面时,它不会。例如:当href相同时,window.location.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> 
+0

尝试location.href.hash:HTTP://计算器.com/questions/5694686/javascript-jump-to-anchor –

+0

在发布问题之前尝试过 - 没有为我工作 –

回答

1

您应该使用ID属性为锚,而不是名称和的location.hash代替location.href

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

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

goToAnchor('happyanchor'); 
</script> 
相关问题