-3
4

3 回答 3

2

如果您需要插入纯文本,请使用.text()

$('.Menu1 a').text('plain text');

但是,如果您希望将文本解释为 HTML,请.html()改用:

$('.Menu1 a').html('<span>this will be interpreted as span</span>');

如果您需要添加内容,而不是替换它,请使用prepend()or append()

$('.Menu1 a').append(' (added after)');
$('.Menu1 a').prepend('(added before) ');

演示

于 2013-10-27T18:21:06.470 回答
1

The following will insert the same text for every matching a:

$('.Menu1 a').text('some text');

If, however, you have a given array of text with which to populate the a elements:

var textStrings = ['Some text for link 1', 'Some different text for link 2', 'Yet more...'];
$('ul li a').text(function(i){
    return textString[i];
});

References:

于 2013-10-27T18:16:30.567 回答
1

是的,使用$('.Menu1 a').html('SOME TEXT');

于 2013-10-27T18:12:08.317 回答