简体   繁体   English

创建DOM元素的扩展方式,还是jQuery的极简替代品?

[英]Ext way to create DOM elements, or minimalist alternative to jQuery?

I have a Sencha Touch application, and I want to create and append to the DOM dynamically for some custom HTML panels. 我有一个Sencha Touch应用程序,我想为某些自定义HTML面板动态创建并附加到DOM。

I really want to be able to do this: 真的很想能够做到这一点:

$('<div><p>Stuff</p></div>')[0] to create DOM elements, but I can't find any such alternative in ExtJS. $('<div><p>Stuff</p></div>')[0]创建DOM元素,但在ExtJS中找不到任何此类替代方法。 Does this sort of "create this big snippet" syntax exist in ExtJS, or is there a smaller library alternative that doesn't require that I pull in all of jQuery? ExtJS中是否存在这种“创建此大片段”语法,或者是否存在不需要我引入所有jQuery的较小的库替代方法?

It also feels a little silly to mix two major frameworks. 将两个主要框架混合在一起也感觉有点愚蠢。

You can just do it the same way that jQuery does it ; 您可以像jQuery一样进行操作 create an element and set the innerHTML property to the HTML code, and get the children of the element: 创建一个元素,并将innerHTML属性设置为HTML代码,并获取该元素的子元素:

var e = document.createElement('DIV');
e.innerHTML = '<div><p>Stuff</p></div>';
var div = e.childNodes[0];

You should just use jQuery. 您应该只使用jQuery。 It's not that big. 没那么大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM