$.each(['a'], function(){$('<a/>').text(this).appendTo('body');});
=> firefox and chrome told me that 'appendTo'开发者_JAVA技巧 is not a function...
You can use:
$.each(['a'], function(idx, elem){$('<a/>').text(elem).appendTo('body');});
Or even better, just use a for loop:
var elements = ['a'];
for (var i in elements) {
$('<a/>').text(elements[i]).appendTo('body');
}
It's both easier to read and faster to execute.
.text() is a function which sets the text, but I don't think you can chain it together. Try opening up that line:
$('a').each(function() {
var a = $('<a/>');
a.text($(this));
$('body').append(a);
});
$('<a/>') should this be $('a')
What are you trying to do?
Perhaps something more like? $('a').each(function(){$('body').append('')});
Doesn't the text function return a string object, not a jQuery object?
加载中,请稍侯......
精彩评论