-1

用户在文本框中输入他的语句后,我必须创建一个链接。

4

2 回答 2

1

How would you create a normal hyperlink?

<a href="...">Hai</a>, How are you

于 2012-12-10T09:18:46.563 回答
1

假设jQuery标签是正确的并且你想要 DOM 操作,这里有一个答案:

http://jsfiddle.net/APUHd/

<button>Link words</button>
<div id="sentence">Hai, How are you</div>​

 

var jqSentence = $('div#sentence');
var aSentence  = jqSentence.html().split(' ');

function LinkWord(iIndex, sHref) {
    aSentence[iIndex] = '<a href="' + sHref + '">' + aSentence[iIndex] + '</a>';
    jqSentence.html(aSentence.join(' '));
}

$('button:first').click(function(){
    LinkWord(1, '/some/path');
    LinkWord(3, '/some/other/path');     
});

​</p>

于 2012-12-10T09:28:55.407 回答