通过</href>后面的代码将数据传递到<area />标签内的<href>标签

时间:2013-12-18 14:19:01

标签: javascript jquery html asp.net

我有一个.ascx页面,我必须在其中显示地图。

<img width="550" height="296" usemap="#Map" alt="" src="~/map_international.jpg">
<map name="Map">
    <area shape="poly" coords="230,84,233,81,236,77,240,74,244,73,247,73,251,76,254,80,258,82,261,83,265,85,269,88,273,87,271,82,273,78,278,75,278,71,281,67,284,70,287,71,291,71,296,73,303,73,306,69,302,62,306,58,312,58,318,58,322,57,322,51,320,46,318,40,319,35,319,31,312,30,308,30,304,30,298,31,292,33,289,33,287,31,279,29,273,27,266,27,259,28,254,33,249,38,244,40,243,44,246,46,249,46,247,50,245,55,241,57,237,58,234,54,231,50,227,47,225,50,221,52,219,57,223,59,228,60,230,64,230,69,229,72,225,73,220,73,218,77,218,82,219,85,223,85,228,85" 
        href="<%# navigationURL+"id?=12"  %>" alt="Europe" title="Europe" >
</map>

navigationURL有一个应用程序路径,我在.cs(代码隐藏)

中为它指定了值

我想要的只是当我在地图中点击这个区域时,它应该导航到href中的给定路径。 但是,当我检查该区域的元素时,href值设置为空。 但如果我对href="www.google.com"中的值进行硬编码,则会导航到Google页面。 但我无法从文件后面的代码中传递数据

2 个答案:

答案 0 :(得分:0)

试试这个:

$(document).ready(function(){
    $("#a").click(function(){
        var href = $(this).next("area").attr("linkto");
        alert(href);
    });
});

实例:http://jsfiddle.net/NE9b7/

答案 1 :(得分:0)

不确定您要执行的操作,因为您键入的代码甚至不应加载页面,因为它无效。您似乎正在尝试使用名为navigationURL的公共字符串来设置为href。所以你的代码背后会有:

public string navigationURL { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
    navigationURL = "someURL?id=12";
}

然后你的href应该是这样的:

href="<%= navigationURL %>"

虽然跳过变量navigationURL并从后面的代码中设置href可能更容易。涉及在id上添加runat="server"area和结束标记:

<area shape="poly" coords="230,84,233,81,236,77,240,74,244,73,247,73,251,76,254,80,258,82,261,83,265,85,269,88,273,87,271,82,273,78,278,75,278,71,281,67,284,70,287,71,291,71,296,73,303,73,306,69,302,62,306,58,312,58,318,58,322,57,322,51,320,46,318,40,319,35,319,31,312,30,308,30,304,30,298,31,292,33,289,33,287,31,279,29,273,27,266,27,259,28,254,33,249,38,244,40,243,44,246,46,249,46,247,50,245,55,241,57,237,58,234,54,231,50,227,47,225,50,221,52,219,57,223,59,228,60,230,64,230,69,229,72,225,73,220,73,218,77,218,82,219,85,223,85,228,85" 
     id="_area" runat="server" alt="Europe" title="Europe" />

然后在代码后面,设置url

_area.Attributes["href"] = "SomeGreatURL";