为什么yui DOM-create方法有一个名为'yui3-big-dummy'的类的处理程序?

xia*_*hao 6 html javascript css yui yui3

在YUI文档中; http://yuilibrary.com/yui/docs/api/files/dom_js_dom-create.js.html

if (nodes.length === 1) { // return single node, breaking parentNode ref from "fragment"
            ret = nodes[0].parentNode.removeChild(nodes[0]);
        } else if (nodes[0] && nodes[0].className === 'yui3-big-dummy') { // using dummy node to preserve some attributes (e.g. OPTION not selected)
            if (nodes.length === 2) {
                ret = nodes[0].nextSibling;
            } else {
                nodes[0].parentNode.removeChild(nodes[0]); 
                ret = Y_DOM._nl2frag(nodes, doc);
            }
        } else { // return multiple nodes as a fragment
             ret = Y_DOM._nl2frag(nodes, doc);
        }
Run Code Online (Sandbox Code Playgroud)

第110行说

} else if(nodes [0] && nodes [0] .className ==='yui3-big-dummy'){//使用虚节点保留一些属性(例如未选择OPTION)

这究竟是什么意思?我不明白为什么会有一个名为'yui3-big-dummy'的班级

Dan*_*ews 2

这是因为他们在自己的内部东西上进一步使用该类,并且他们只是不想将一个有人实际使用的类放在那里。您会注意到,在第 317 行,他们正在使用该类将一些内容放入其中,并且他们正在尝试以该类为目标。这只是一些您通常不必担心的内部问题。

return Y_DOM.create('<select><option class="yui3-big-dummy" selected></option>' + html + '</select>', doc);
Run Code Online (Sandbox Code Playgroud)