[英]how to redirect on same page area on button click without postback?
On clicking button I want users to be redirected to some specific area in same page. 在单击按钮时,我希望用户被重定向到同一页面中的某些特定区域。 I know it can be done with using anchor tags but not sure how will it possible with asp.button.
我知道可以通过使用锚标记来完成,但是不确定使用asp.button怎么可能。 On clicking button I want the user to redirect to a place holder.
在单击按钮时,我希望用户重定向到占位符。 Please guide me how to do this.
请指导我如何执行此操作。
Thanks 谢谢
使用<a href="#xxx">
标记,其中xxx
是页面中某处的<a name="xxx">
标记。
The easy way, with out any check, just use javascript to add the anchor at the end of the link . 简单的方法,无需任何检查,只需使用javascript在链接的末尾添加锚即可。
<asp:Button ID="Button1" runat="server"
OnClientClick="document.location.href+='#locA';return false;" />
and it will navigate to position of the : <a name="locA"></a>
它将导航到
<a name="locA"></a>
and the correct way, that you can make many clicks with diferent anchors. 正确的方法是,您可以使用不同的锚点进行多次点击。
<script>
function cGoTo(where)
{
// take care if any other anhor exist to remove it.
var url = document.location.href
var tempArray = url.split("#");
var baseURL = tempArray[0];
document.location.href = baseURL + "#" + where;
}
</script>
<asp:Button ID="Button2" runat="server" OnClientClick="cGoTo('locA');return false;" />
And one online test: http://jsfiddle.net/r3Sav/ 还有一项在线测试: http : //jsfiddle.net/r3Sav/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.