读书人

!javascript怎么实现这个功能啊

发布时间: 2012-05-30 20:20:04 作者: rapoo

求助!javascript如何实现这个功能啊?
后台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函数,实现鼠标点击就跳到相应的地址?

[解决办法]

HTML code
<!DOCTYPE HTML><html>    <head>        <meta charset="gb2312" />        <title></title>    </head>    <body>        <textarea id="test">            202.54.10.123            200.54.10.124            202.54.10.125        </textarea>        <br />        <script>            function $(el){                return typeof el == 'string' ? document.getElementById(el) : el;            }            var str = $('test').value;            var re = /.+\n/g;            alert(str.match(re))            str.replace(re, function($){                document.write( '<a href="http://'+$+'" target="_blank">'+$+'</a><br />' );            })        </script>    </body></html>
[解决办法]
经过测试 这个是正解
<table>
<tr>
<td>
<script>
var a='<%=Url%>'.split("<br/>")
for(var i=1;i<a.length-1;i++){
document.write("<a href='http://" + a[i] + "'>" + a[i] + "</a><br/>")
}

</script> <td>
</tr>
</table>

读书人网 >JavaScript

热点推荐