Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何向网页添加自定义超链接_Asp.net_Vb.net - Fatal编程技术网

Asp.net 如何向网页添加自定义超链接

Asp.net 如何向网页添加自定义超链接,asp.net,vb.net,Asp.net,Vb.net,我想在我的网页上添加一个超链接到一个社交书签站点,该站点要求我包含发送它的网页的名称 我正在努力实现的示例: 当前页面为: 我要在上述页面上创建的超链接: 以编程方式将此自定义超链接添加到网页的最简单方法是什么?使用jQuery: $(document).ready(function(){ $("a.stumblethis").each(function(){ $(this).attr("href", "http://www.stumbleupon.com/sub

我想在我的网页上添加一个超链接到一个社交书签站点,该站点要求我包含发送它的网页的名称

我正在努力实现的示例:

当前页面为:

我要在上述页面上创建的超链接:

以编程方式将此自定义超链接添加到网页的最简单方法是什么?

使用jQuery:

$(document).ready(function(){
    $("a.stumblethis").each(function(){
          $(this).attr("href", "http://www.stumbleupon.com/submit?url="+$(this).attr("href"));
        });    
});
这将使用jQuery转换具有“stumblethis”类的所有链接

$(document).ready(function(){
    $("a.stumblethis").each(function(){
          $(this).attr("href", "http://www.stumbleupon.com/submit?url="+$(this).attr("href"));
        });    
});

这将转换具有“stumblethis”类的所有链接。

假设您有这样的超链接:

<asp:HyperLink runat="server" ID="myLink" Text="stumbleupon"></asp:HyperLink>
或者另一种方法(我认为这一种更容易):


假设您有这样的超链接:

<asp:HyperLink runat="server" ID="myLink" Text="stumbleupon"></asp:HyperLink>
或者另一种方法(我认为这一种更容易):


我支持卡纳瓦尔的回答。在构建超链接时,您可能还希望对currentPagesUrl字符串进行URL编码:

myLink.NavigateUrl=string.Format(“{0}”,

UrlEncode(currentPagesUrl))

我支持卡纳瓦尔的回答。在构建超链接时,您可能还希望对currentPagesUrl字符串进行URL编码:

myLink.NavigateUrl=string.Format(“{0}”,

UrlEncode(currentPagesUrl))

我们无法连接到我们无法连接到HttpContext.Current.Request.Url.AbsoluteUri不应该是Url编码的吗?HttpContext.Current.Request.Url.AbsoluteUri不应该是Url编码的吗?成本很高(在文档中的每个节点循环),并且不适用于不支持javascript的客户端,这就是为什么您会得到我的建议-1@Clement-赫雷曼:(1)是的,如果他们没有javascript,它将不起作用,但问题并没有指定不能使用javascript。(2) jQuery可以利用浏览器提供的函数getElementsByTagName和GetElementsByCassName来高效地查找正确的元素。成本很高(循环遍历文档中的每个节点),并且不适用于不支持javascript的客户端,这就是为什么您会得到我的-1@Clement-赫雷曼:(1)是的,如果他们没有javascript,它将不起作用,但问题并没有指定javascript不能被使用。(2) jQuery可以利用浏览器提供的函数getElementsByTagName和getElementsByClassName高效地查找正确的元素。
myLink.NavigateUrl = string.Format("http://www.stumbleupon.com/submit?url={0}",
    Server.UrlEncode(currentPagesUrl));