如何使用 javascript 创建链接? [英] How do I create a link using javascript?

查看:31
本文介绍了如何使用 javascript 创建链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标题字符串和一个链接字符串.我不确定如何将两者放在一起以使用 Javascript 在页面上创建链接.任何帮助表示赞赏.

I have a string for a title and a string for a link. I'm not sure how to put the two together to create a link on a page using Javascript. Any help is appreciated.

为问题添加更多细节.我试图弄清楚这一点的原因是因为我有一个 RSS 提要,并且有一个标题和 URL 列表.我想将标题链接到 URL 以使页面有用.

Adding more detail to the question. The reason I'm trying to figure this out is because I have an RSS feed and have a list of titles ands URLs. I would like to link the titles to the URL to make the page useful.

我正在使用 jQuery,但我对它完全陌生,不知道它在这种情况下会有所帮助.

I am using jQuery but am completely new to it and wasn't aware it could help in this situation.

推荐答案

<html>
  <head></head>
  <body>
    <script>
      var a = document.createElement('a');
      var linkText = document.createTextNode("my title text");
      a.appendChild(linkText);
      a.title = "my title text";
      a.href = "http://example.com";
      document.body.appendChild(a);
    </script>
  </body>
</html>

这篇关于如何使用 javascript 创建链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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