我正在编写一个 javascript 代码:
$('div').html(<some text>).find('>')
看jQuery文档,看不懂是什么find('>')
应该做的。
此外,在导航器控制台中进行试验时,我得到了奇怪的结果:
$('div').html('to<br/>to').find('>')
-> [ <br>, <br>, <br>]
$('div').html('to<a/>to').find('>')
-> [ <a></a>, <a></a>, <a></a>]
为什么要重复 3 次?
所以,谁能告诉我这个奇怪的find('>')
?
最佳答案
>
是 Child Combinator CSS selector . .find('>')
将提取该元素的所有直接子元素。
如评论中所述,重复必须是由于您的文档具有多个 div
元素。
更新
来自 your comment :
I thought the line was creating a div then setting some html into it.
$('div')
本身会选择文档中存在的所有 div
元素。如果你想创建一个 div
元素,你可以这样做:
$('<div/>', { html: 'to<br/>to' });
如果您是 jQuery 新手,我强烈建议您查看 http://try.jquery.com和 http://learn.jquery.com .
关于javascript - jquery find ('>' 的含义和用法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22537216/