我想用JSON分隔一些单词,并用JSON打印带下划线的单词
示例JSON数据:{'term':'word1','term':'word2','term':'word3',..}
我做了什么?
function wrapSentence(sentence) {
$.getJSON( "ajax/test.json", function( data ) {
var items = [];
$.each( data, function( key, terms ) {
// Get element contents and split by whitespace git
var words = $sentence.text().split(/\s+/);
// Create an empty array for storing wrapped elements
var wrapped = [];
// Loop through each word and wrap
for (var i = 0; i < words.length; i++) {
if(words[i] != terms) {
wrapped.push('<span>' + words[i] + '</span>');
} else {
wrapped.push('<span style="text-decoration: underline;text-decoration-style:dashed;">' + words[i] + '</span>');
}
}
// Combine words into a string
return wrapped.join(' ');
});
});
}
我可以使用getJSON获取数据,但无法打印。 可能是什么原因?