使用jQuery动态创建链接

我正在尝试使用jQuery在blockquote元素中创建一个链接。 现在我正处于这个阶段:

var pullQuote = $('span.pull-quote').each(function(){ var $this = $(this), hrefLink = 'http://example.com', text = $this.text(); $('
', { class: 'quote', text: text }).prependTo( $this.closest('p')); });

这会创建带有文本动态的blockquote元素,但我想将文本转换为blockquote内的链接。 href不会改变所以我可以在变量中设置它,就像我已经拥有它一样。

我可以添加一些能够在blockquote中创建一个标签的东西,我仍然可以使用set变量吗? (这是我一直在尝试做的)或者我是否需要运行此函数然后创建一个新函数来处理添加链接?

 $('
', { class: 'quote', html: $('', { text: text, href: hrefLink )} }).prependTo( $this.closest('p'));

如果我理解你正确,你只是想在blockquote中构造一个锚元素并给出文本和链接。

 var $this = $(this); hrefLink = 'http://example.com'; text = $this.text(); var blockQ=$('
'+text+'
'); blockQ.prependTo( $this.closest('p'));

演示: http : //jsfiddle.net/QGtYQ/5/