2012-09-14 13 views
1

如何从JavaScript中将data-theme值添加到所有div,listviews,forms,li,ul等?
可能吗?如果是,我该怎么做?将数据主题添加到所有项目

会像下面的工作?

$.mobile.page.prototype.options.contentTheme= "e"; 

回答

1
Array.prototype.forEach.call(document.getElementsByTagName("*"), function (el) { 
    el.setAttribute("data-theme", "e"); 
}); 
1

如果您有包括jQuery的移动,下面应该工作:

$.mobile.page.prototype.options.contentTheme= "e"; 
$.mobile.page.prototype.options.headerTheme= "e"; 
$.mobile.page.prototype.options.footerTheme= "e"; 

但是,如果你补充说,不是的标题,内容或页脚部分的任何元素,那么你应该去用Domenic的方式申请每一个元素

+0

这看起来比我的版本更好,我想......它来自一个真正认识jQuery手机的人:) – Domenic