且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么这个jQuery引用'$("< div />")'而不是'$("< div>< / div>")''?

更新时间:2022-12-08 11:22:20

从技术上讲,如果你使用 $('< div />') $(无) '< div>< / div>')

Technically it doesn't matter if you use $('<div />') or $('<div></div>').

这段代码正在做的是创建一个新的div元素,添加一些css样式,添加id,定位,将其附加到身体然后隐藏它。

What this code is doing is creating a new div element, adding some css styles to it, adding an id, positioning it, appending it to the body and then hiding it.

我猜jQuery使用document.createElement来创建元素,这意味着浏览器知道如何渲染它。

I'm guessing jQuery uses document.createElement to create the element and that means the browser knows how to render it.