我在互联网上找到了这段代码.它需要一个句子,并使每个单词与该单词链接.但它有一个弱点:如果一个句子中有HTML,这个脚本不会删除它.
例如:它取代' asserted'with' http://www.merriam-webster.com/dictionary/asserted'
你能告诉我在这段代码中要改变什么来改变' asserted'到' http://www.merriam-webster.com/dictionary/asserted'.
var content = document.getElementById("sentence").innerHTML;
var punctuationless = content.replace(/[.,\/#!$%\?^?&\*;:{}=\-_`~()”“"]/g, "");
var mixedCase = punctuationless.replace(/\s{2,}/g);
var finalString = mixedCase.toLowerCase();
var words = (finalString).split(" ");
var punctuatedWords = (content).split(" ");
var processed = "";
for (i = 0; i < words.length; i++) {
processed += "";
processed += punctuatedWords[i];
processed += " ";
}
document.getElementById("sentence").innerHTML = processed;