• <tfoot id='i211y'></tfoot>

    1. <small id='i211y'></small><noframes id='i211y'>

    2. <legend id='i211y'><style id='i211y'><dir id='i211y'><q id='i211y'></q></dir></style></legend>
        <bdo id='i211y'></bdo><ul id='i211y'></ul>
    3. <i id='i211y'><tr id='i211y'><dt id='i211y'><q id='i211y'><span id='i211y'><b id='i211y'><form id='i211y'><ins id='i211y'></ins><ul id='i211y'></ul><sub id='i211y'></sub></form><legend id='i211y'></legend><bdo id='i211y'><pre id='i211y'><center id='i211y'></center></pre></bdo></b><th id='i211y'></th></span></q></dt></tr></i><div id='i211y'><tfoot id='i211y'></tfoot><dl id='i211y'><fieldset id='i211y'></fieldset></dl></div>

      1. 哪个是使用 jQuery 创建新元素的正确或更好的方法?

        时间:2023-07-31

          <tfoot id='YlBaT'></tfoot>

          <legend id='YlBaT'><style id='YlBaT'><dir id='YlBaT'><q id='YlBaT'></q></dir></style></legend>

            <small id='YlBaT'></small><noframes id='YlBaT'>

              <tbody id='YlBaT'></tbody>
            • <bdo id='YlBaT'></bdo><ul id='YlBaT'></ul>
              • <i id='YlBaT'><tr id='YlBaT'><dt id='YlBaT'><q id='YlBaT'><span id='YlBaT'><b id='YlBaT'><form id='YlBaT'><ins id='YlBaT'></ins><ul id='YlBaT'></ul><sub id='YlBaT'></sub></form><legend id='YlBaT'></legend><bdo id='YlBaT'><pre id='YlBaT'><center id='YlBaT'></center></pre></bdo></b><th id='YlBaT'></th></span></q></dt></tr></i><div id='YlBaT'><tfoot id='YlBaT'></tfoot><dl id='YlBaT'><fieldset id='YlBaT'></fieldset></dl></div>

                  本文介绍了哪个是使用 jQuery 创建新元素的正确或更好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  与https://stackoverflow.com/a/10619477/1076753的答案相关,清除一个元素更好使用

                  Related to the answer https://stackoverflow.com/a/10619477/1076753 to cleate an element is better to use

                  $("<div>", {id: "foo", class: "a"});
                  

                  $("<div />", {id: "foo", class: "a"});
                  

                  它们都有效,但哪个更好或更正确?

                  They both works, but which is better or correct to use?

                  官方的API Documentation说要保证跨平台的兼容性,snippet一定要好-形成.可以包含其他元素的标签应与结束标签配对:

                  The official API Documentation says that to ensure cross-platform compatibility, the snippet must be well-formed. Tags that can contain other elements should be paired with a closing tag:

                  $( "<a href='http://jquery.com'></a>" );
                  

                  虽然不能包含元素的标签可能会被快速关闭:

                  while Tags that cannot contain elements may be quick-closed or not:

                  $( "<img>" );
                  $( "<input>" );
                  

                  那么,最后将前两个选项之一用于 div 是错误的吗?

                  So, at the end it's wrong to use one of the first two options for a div?

                  推荐答案

                  如果你只使用易于衡量的指标:第一个更好,因为它短 2 个字节.

                  If you go solely by metrics that can be easily measured: The first is better because it is 2 bytes shorter.

                  一旦您开始考虑可读性和其他不太具体的考虑因素,它在很大程度上就变成了一个见仁见智的问题.

                  Once you start accounting for readability and other less tangible considerations, it becomes largely a matter of opinion.

                  那么,最后将前两个选项之一用于 div 是错误的吗?

                  So, at the end it's wrong to use one of the first two options for a div?

                  不,该部分仅适用于如果 HTML 比没有属性的单个标记更复杂"

                  No, that section only applies "If the HTML is more complex than a single tag without attributes"

                  这篇关于哪个是使用 jQuery 创建新元素的正确或更好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用正则表达式用逗号分隔的rails自动完成标签 下一篇:如何在 jquery 中用另一个标签替换 HTML 标签?

                  相关文章

                1. <legend id='dvvwQ'><style id='dvvwQ'><dir id='dvvwQ'><q id='dvvwQ'></q></dir></style></legend>

                    <tfoot id='dvvwQ'></tfoot>
                  1. <i id='dvvwQ'><tr id='dvvwQ'><dt id='dvvwQ'><q id='dvvwQ'><span id='dvvwQ'><b id='dvvwQ'><form id='dvvwQ'><ins id='dvvwQ'></ins><ul id='dvvwQ'></ul><sub id='dvvwQ'></sub></form><legend id='dvvwQ'></legend><bdo id='dvvwQ'><pre id='dvvwQ'><center id='dvvwQ'></center></pre></bdo></b><th id='dvvwQ'></th></span></q></dt></tr></i><div id='dvvwQ'><tfoot id='dvvwQ'></tfoot><dl id='dvvwQ'><fieldset id='dvvwQ'></fieldset></dl></div>
                        <bdo id='dvvwQ'></bdo><ul id='dvvwQ'></ul>

                      <small id='dvvwQ'></small><noframes id='dvvwQ'>