使用Javascript将URL转换为可点击的链接 [英] Converting URL into clickable link using Javascript

查看:81
本文介绍了使用Javascript将URL转换为可点击的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单中有一个名为'patentURL'的文本字段。用户在保存记录时将完整的URL输入到该字段中。当用户搜索此记录时,输入的URL应该是可点击的。即在结果页面中,输入的URL应该是可点击的。



如何使用Javascript实现此目的?

 < / p>如果我理解正确,应该将链接放在链接中:

a href =URL_ENTERED> URL_ENTERED< / a>

使用javascript:

  var link = document.createElement('a'); //创建链接
link.setAttribute('href','URL_ENTERED'); //设置href
link.innerHTML ='URL_ENTERED'; //设置要显示的文本
document.body.appendChild(link); //添加到body


I have a text field called 'patentURL' in a form. The user enteres the complete URL into this field while saving the record. When the user searches for this record, the entered URL should be clickable. i.e. in the result page, the entered URL should be clickable.

How do I achieve this using Javascript?

解决方案

If i understood correctly you should put the url in a link:

<a href = "URL_ENTERED">URL_ENTERED</a>

With javascript:

var link = document.createElement('a');//create link
link.setAttribute('href', 'URL_ENTERED');//set href
link.innerHTML = 'URL_ENTERED';//set text to be seen
document.body.appendChild(link);//add to body

这篇关于使用Javascript将URL转换为可点击的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆