一个Var,多个createElement
one Var, multiple createElement
我正在从js创建一个html结构。
var e = document;
// HTML Tree
$this.append(
$(e.createElement('div')).addClass('wood-bottom'),
$(e.createElement('div')).addClass('jalendar-wood')
.append(
$(e.createElement('div')).addClass('jalendar-pages')
.append(
$(e.createElement('div')).addClass('pages-bottom'),
$(e.createElement('div')).addClass('header'),
$(e.createElement('div')).addClass('total-bar'),
$(e.createElement('div')).addClass('days')
)
)
);
并且存在如此多的CCD_ 1语句。
这种方法有更好的解决方案吗?如果我定义var e = document.createElement('div')
,它不会像我想要的那样工作。
自定义函数怎么样?
var div = function(klass){return $(document.createElement('div')).addClass(klass)};
// HTML Tree
$this.append(
div('wood-bottom'),
div('jalendar-wood')
.append(
div('jalendar-pages')
.append(
div('pages-bottom'),
div('header'),
div('total-bar'),
div('days')
)
)
);
您可以使用jQuery克隆():
var e = document;
var $d = $(e.createElement('div'));
$this.append(
$d.clone().addClass('wood-bottom'),
$d.clone().addClass('jalendar-wood')
.append(
$d.clone().addClass('jalendar-pages')
[...]
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 多个单选按钮组相互干扰
- onkeyup无法动态创建多个文本区域
- 借助asp.net验证或java脚本对多个文本进行验证
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- jQuery自定义验证比较多个输入的序列
- Html页面上的多个Base64图像和平滑加载
- 使用javascript检查多个输入值,并在1次检查中标记多个输入框
- KnockoutJS-组件-多个实例
- 科尔多瓦页面类应用程序中的多个谷歌地图
- 选中多个具有相同名称的复选框
- MongoDB (php) - 以数组而不是多个属性的形式返回文档属性
- 如何将一个JavaScript函数回调为多个函数
- 循环浏览多个身体背景图像
- 谷歌地图JS API+JSON-多个标记没有显示
- 如何将多个画布保存为一个图像
- 使用$.ajax发布多个复选框
- 多个 document.createElement 在一个函数中返回事件侦听器
- 一个Var,多个createElement
- 有没有一种速记的方法来记录.createElement多个元素