我想要做的是创建一个按钮并按下此按钮,它将更改我的jQuery移动测试网站上的主题颜色。jQuery附加到元素
所以说,我的HTML父DIV看起来像这样
<div id="firstPage" data-role="page">
我想它使上点击,它附加data-theme="theme letter here"
到div,使其结束了这样<div id="firstPage" data-role="page" data-theme="theme letter here">
OR
如果我像这样开始div <div id="firstPage" data-role="page" data-theme="theme letter here">
在按钮上单击,它将数据主题属性更改为另一个字母
这样的东西,例如,像这样
$('#themeBtn').click(function(){
$('#firstPage').setAttribute("data-role","ANOTHER theme letter");
});
或
$('#themeBtn').click(function(){
$('#firstPage').append("data-role","a");
});
或这样的事情。我该如何正确地去做这件事?
谢谢先进。
编辑*基础上的反应,我用尽**
/////////////TESTING THEME BUTTON (check STACK OVERFLOW for answer)
$('#themeBtn').click(function(){
//$('#firstPage').jqmData("role","a");
//$('#firstPage').attr("data-theme","a");
//$('#firstPage').jqmData("theme","a");
$('#firstPage').data('theme','a');
});
为了确保该按钮被解雇了,我注释掉那些行,做一个简单的
$('#themeBtn').click(function(){
alert("foo");
});
,果然它在按钮点击时发出警报,所以即时通讯正在工作(按钮我的意思是)。
我加了的jsfiddle所以你可以看到它在行动(不工作的笑) http://jsfiddle.net/somdow/yRmKd/1/ 如果取消注释警报,ITLL断火,当你取消对其它线路(基于响应)它不更新。
不jQuery Mobile的使用jqmData()呢? docs:http://jquerymobile.com/test/docs/api/methods.html –
@ZathrusWriter感谢指出,将编辑:) –
你好,感谢您的答复,我编辑我的帖子,以显示什么是基于答复,而且不起作用。 – somdow