我想在asp.net應用程序
我有textarea的,當我輸入的文本,如果它包含像www.google.com或http://google.com然後我希望得到textarea的值的各個環節或第一鏈路鏈接來從文本框URL鏈接。
我如何用Jquery或javascript語言實現。 當我在textarea控件中輸入文字/文本時,我想獲得每個或第一個鏈接。這裏我寫了一些代碼。如何從整個文本中獲取網站網址?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test Page </title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="innerWrap">
<textarea autocomplete="off" id="txtUpdate" style="height: 48px; width: 408px;" >
</textarea>
</div>
</div>
<script>
$(document).ready(function(){
$('#txtUpdate').keyup(function() {
getURLfromText(jQuery.trim($(this).val()));
});
});
function getURLfromText(objTxt)
{
// code
}
</script>
</form>
</body>
</html>
請給我正確的解決方案。 也應該是我複製並粘貼一些文本的作品。 怎麼可能。?
編輯
輸入
Down to Earth: Tracy Caldwell Dyson www.google.com
After spending nearly six months in space,
she is back on the ground, with two expeditions
under her belt. http://bit.ly/dEpNHo
輸出
Array linkarray[]=new Array();
linkarray[0]="www.google.com";
linkarray[1]="http://bit.ly/dEpNHo";
你有一個未關閉的div BTW – corroded 2011-03-23 10:28:02
@corroded對不起,我離開封閉div標籤..現在固定。 – 2011-03-23 10:30:02