当href是同一页时,Window.location.href不工作
window.location.href not working when href is same page
我有一个输入表单,它接受报告的参数。我把这些提交到同一个页面。当生成报表时,我希望将用户移动到报表的顶部。然而,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>
您应该使用id属性来代替名称和位置。hash代替location.href
<div id="happyanchor"></div>
<script>
function goToAnchor(anchor){
location.hash = anchor;
}
goToAnchor('happyanchor');
</script>
相关文章:
- 如何将所有作业自定义到window.location.href
- 如果window.location.href.indexOf('player=1')添加样式
- 可以'当window.location.href时,无法从javascript获取post值
- window.location.href/reload导致AngularJS[$rootScope:infdig]达到1
- 当用户在选择框中选择选项时,使用window.location.href重定向用户只会更改导航器中URL的最后一位
- window.location.href =“#find” 适用于移动设备,但不适用于 PC.在本地站点上正常(表达式
- Javascript-将变量传递给php页面,window.location.href不起作用
- 后退按钮在 window.location.replace(href);之后失败
- 在window.location.href中使用php
- 如何在Jquery Mobile和RequireJS中使用window.location.href时避免出现空白页
- 无法在Chrome中捕获Chrome window.location.href
- ie与chrome window.location.href和<基本>标签
- window.location.href窗口未在javascript中定义
- 脏表单 - 如何忽略在parent.window.location.href上弹出的脏表单
- 使用window.location.href进行完全重定向
- javascript window.reload then window.location.href
- window.location.href未设置查询参数
- 页面加载方式不同,window.location与href:
- window.location.href = window.location.href and JSLint
- JavaScript:window.location.href/window.open 在 iframe 上不起作用