所以我有這樣的功能在這裏:檢查文本區域玲,並將其轉變成超級鏈接
function ShowMessage()
{
var themessege = document.getElementById("Form").textarea1.value;
var dat = new Date();
var fileName = document.getElementById("theFile").value;
var image = '<img src="' + fileName + '"/>' + '<br>';
document.getElementById("Form").textarea1.value = "";
document.getElementById("Form").countdown.value = "160";
document.getElementById("theFile").value = "";
if (themessege==null || themessege=="")
{
alert("There is no text to submit, please fill out the text box");
return false;
}
document.getElementById("blog").innerHTML = document.getElementById("blog").innerHTML + image + "Guest post: " + themessege + "<br />" + dat +"<br />";
}
我可以從文本區域中的文本,以及圖像用戶上傳。我想知道如何將文本區域中的字符串劃分爲子項以檢查它們是以「www」還是「htt」開頭。
這是我到目前爲止已經寫的:
function linkify(inputText) {
var replaceText, replacePattern1, replacePattern2;
//URLs starting with http://, https://
replacePattern1 =https;
replacedText = inputText.replace(replacePattern1, '<a href= ></a>');
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = www.;
replacedText = replacedText.replace(replacePattern2, <a href="http: ></a>');
var x = getelementbyid("blog");
for(var i = 0;i < x.length;i++){
if(blog.charAt(i) == replacePattern1){
return replacedText;
}
}
else if(blog.charAt(i) == replacePattern2){
return replacedText;
}
}
我知道charAt(i)
只爲1個字母檢查....
大多數,我發現是在PHP的答案,我試圖找到一個使用JavaScript的解決方案。
你的功能只是取代了的鏈接,並以功能名稱來判斷,我不相信這就是他想要的。我相信他希望它實際上成爲一個可點擊的超鏈接。 –
是的,我想成爲一個可點擊的超鏈接 –