HyperLink1重定向页面

时间:2011-03-27 14:17:36

标签: javascript jquery-ui jquery jquery-selectors

脚本

 function getParam(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.href);
            if (results == null)
                return "";
            else
                return unescape(results[1]);
        }

HTML

 <asp:HyperLink ID="HyperLink1" runat="server" 
                    NavigateUrl="~/PersonPage/ConfighMessages.aspx?idCompany=javascript:getParam('idCompany');">bbb</asp:HyperLink>

我想如果在网址中idCompany=123将此HyperLink重定向到PersonPage/ConfighMessages.aspx?idCompany=123

但此代码重定向到:/PersonPage/ConfighMessages.aspx?idCompany=getParam('idCompany');

2 个答案:

答案 0 :(得分:0)

$(<%= "#"+HyperLink1.ClientID %>).attr("href","/PersonPage/ConfighMessages.aspx?idCompany="+ getParam('idCompany'));

<asp:HyperLink ID="HyperLink1" runat="server" 
                    NavigateUrl='<%= "~/PersonPage/ConfighMessages.aspx?idCompany=" + Request.QueryString["idCompany"]%>'>bbb</asp:HyperLink>

答案 1 :(得分:0)

javascript:getParam('idCompany')无效。

尝试:

$("#HyperLink1").click(function(){
    window.location.href = "~/PersonPage/ConfighMessages.aspx?idCompany="+idCompany;
});