日期:2014-05-18  浏览次数:20852 次

求助! 如何分割字符串后用超链接点击打开??
后台default.aspx.cs: 
public string Url = "<br/>202.54.10.123<br/>200.54.10.124<br/>202.54.10.125<br/>";

前台default.aspx:
 <table>
  <tr>
  <td>
  <a href="javascript:ShowUrl(<%=Url%>)"><%=Url%></a>
  <td>
  </tr>
 </table>

  请问如何写一个ShowUrl函数,实现鼠标点击就跳到相应的地址?

------解决方案--------------------
public string Url = "<br/>202.54.10.123<br/>200.54.10.124<br/>202.54.10.125<br/>";
Url = Url.Replace("<br/>"," ").Trim();

<a href="javascript:ShowUrl('<%=Url%>')"><%=Url%></a>

function ShowUrl(s)
{
 s = s.split(" ")
 for(x in s)
 window.open(s[x],"_blank")
}

HTML code
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">


  public string Url = "<br/>202.54.10.123<br/>200.54.10.124<br/>202.54.10.125<br/>";
  protected void Page_Load(object sender, EventArgs e)
  {
    Url = Url.Replace("<br/>", " ").Trim();
  }


</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
  <form id="form1" runat="server">
  <a href="javascript:ShowUrl('<%=Url%>')">
    <%=Url%></a>
  <script type="text/javascript">
    function ShowUrl(s) {
      s = s.split(" ")
      for (x in s)
        window.open("http://"+ s[x], "_blank")
    }
  </script>
  </form>
</body>
</html>