[英]Update data-theme after page load with jquery mobile
I have a couple of buttons in a control group to represent on/off and I want to switch their themes when clicked. 我在控制组中有几个按钮来表示开/关,我想在点击时切换它们的主题。 I am able to change the theme when I click on one of the buttons, but once I move the mouse so it isn't hovering over it, it changes the theme back to what it was before.
当我点击其中一个按钮时,我可以更改主题,但是一旦我移动鼠标使其不会悬停在它上面,它就会将主题更改回原来的状态。 How can I make the theme stick?
我该如何制作主题贴? Here is my buttons and javascript:
这是我的按钮和javascript:
<div data-role="controlgroup" data-type="horizontal">
<div title="lights.MyLight.ON" data-role="button">ON</div>
<div title="lights.MyLight.OFF" data-role="button" data-theme="b">OFF</div>
</div>
$("div[title]").click(function() {
var action = this.title;
jQuery.fn.log(action);
$.ajax({
url: 'do.php?a='+action,
cache: false
});
var cls = this.getAttribute('class');
var pcs = cls.split(" ");
var color = "";
cls = "ui-btn " + pcs[1];
if(pcs.length > 3)
{
color = pcs[3].split("-");
cls = cls + " ui-controlgroup-last"
}
else
{
color = pcs[2].split("-");
}
cls = cls + " ui-btn-up-b";
this.setAttribute('data-theme', 'b');
this.setAttribute('class', cls);
});
首先,您需要将class
属性添加到div
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.