我正在尝试获取文本输入的值并检查其中是否有任何链接,然后获取这些链接并将它们制作成标签。但是当我运行这段代码时,出现了问题,它完全冻结了页面。基本上,我希望它检查“http://”,如果存在,继续添加 substr 长度,直到字符串/链接结束。有一个更好的方法吗?
// the id "post" could possibly say: "Hey, check this out! http://facebook.com"
// I'd like it to just get that link and that's all I need help with, just to get the
// value of that entire string/link.
var x = document.getElementById("post");
var m = x.value.indexOf("http://");
var a = 0;
var q = m;
if (m != -1) {
while (x.value.substr(q, 1) != " ") {
var h = x.value.substr(m, a);
q++;
}
}