那么如何实现将字符串如
my website:http://cutepig.9126.com or http://sdhe.9126.com
转换为
my website:<a href=http://cutepig.9126.com>http://cutepig.9126.com</a> or <a href=http://sdhe.9126.com>http://sdhe.9126.com</a>
多谢了。主要是算法的问题。
<div id="dvHTML"></div>
<form name="form1">
<input type="text" name="txtLink" value="csdn">
<input type="text" name="txtURL" value="http://www.csdn.net"><br>
<input type="button" value="create link with js" onclick="javacript:createLink(this.form.txtLink.value, this.form.txtURL.value)">
<input type="button" value="create link with vbs" onclick="vbscript:call createLink2(me.form.txtLink.value, me.form.txtURL.value)">
</form>
<script language="javascript">
function createLink(txt,url)
{
var a = document.createElement("A");
a.href = url;
a.innerHTML = txt;
document.getElementById("dvHTML").appendChild(a);
}
</script>
<script language="vbscript">
sub createLink2(txt,url)
dim a
set a = document.createElement("A")
a.href = url
a.innerHTML = txt
document.getElementById("dvHTML").appendChild(a)
end sub
</script>