本文介绍了jQuery中的$('< element>')与$('< element/>')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到人们以两种不同的方式在jQuery中创建HTML元素:
I see people creating HTML elements in jQuery in two different ways:
$('<element>')
和
$('<element />')
我很好奇哪个是更正确的".我认为第一个方法的明显优势是只需键入很少的内容.使用哪一个完全不同?
I am curious which one is "more correct". I see the obvious advantage to the first one as being just simply less to type. Does it make a difference at all which one is used?
推荐答案
正如源代码& 第121行:
There is no difference, as seen in the source code, line 30 & line 121:
/* Line 30*/
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
/* Line 121 */
// If a single string is passed in and it's a single tag
// just do a createElement and skip the rest
ret = rsingleTag.exec( selector );
以下等同:
-
<a></a>
-
<a />
-
<a>
<a></a>
<a />
<a>
这篇关于jQuery中的$('< element>')与$('< element/>')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!