0

如何从后面的 asp.net 代码中传递 this.href?这是我所拥有的,在 javascript 中我添加了一个警报以查看该值,它显示“未定义”

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript(this.href);", true);

function Callscript(href) 
{
    alert(href);
}
4

3 回答 3

2

href不是全局对象的属性。我相信您正在寻找window.location.href

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript(window.location.href);", true);
于 2012-05-29T19:39:29.210 回答
0

您没有正确传递 aspx.cs 文件中的 href。它应该如下所示。

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript('" + this.href + "');", true);  

function Callscript(href)  
{     
    alert(href); 
}

希望这可以帮助!!

于 2012-05-29T19:32:10.147 回答
0

“这个”是两个不同的东西——它是服务器上的一个东西,另一个是客户端上的东西。

您可以尝试像这样修改您的启动脚本:

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript('" + this.href + "');", true);
于 2012-05-29T19:34:46.180 回答