[英]Changing JQuery Mobile data-theme dynamically
I want to map a tap event to a function that changes the data-theme of a specific element in my document. 我想将tap事件映射到一个函数,该函数会更改文档中特定元素的数据主题。 It looks something like this:
看起来像这样:
$(document).delegate("#item1", "tap", function() {
$("#item1").attr("data-theme", "e");
});
So far, it kind of works correctly. 到目前为止,它可以正常工作。 In the source code I can see it changing the attribute.
在源代码中,我可以看到它正在更改属性。 However, it doesn't get re-rendered on the document and everything appears to the stay the same.
但是,它不会在文档上重新呈现,并且所有内容看起来都一样。 Do I have to reload the document or is there a way to make it dynamically update?
我是否需要重新加载文档,或者有办法使其动态更新?
First use .on and vclick instead of delegate and tap. 首先使用.on和vclick而不是委托和点击。 You can read on vclick here , read on .on here
你可以阅读V单击这里 ,阅读。对在这里
You need to trigger refresh event, than jquery mobile will apply styling to that element again, for example if you change a list view, you can do this 您需要触发刷新事件,然后jQuery mobile将再次将样式应用于该元素,例如,如果您更改列表视图,则可以执行此操作
$("#listview").listview('refresh')
In case you want styling changed on an element that has no refresh event, you can trigger page create event on the whole page, that will refresh everything. 如果要在没有刷新事件的元素上更改样式,则可以在整个页面上触发页面创建事件,该事件将刷新所有内容。
$('#pageid').trigger('create')
Check here to see which elements have refresh event 在此处查看哪些元素具有刷新事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.