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

查看:100
本文介绍了如何使用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.

EDIT1:添加更多的细节问题。
我想解决这个问题的原因是因为我有一个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.

EDIT2:我正在使用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天全站免登陆