问题描述
我想将tap事件映射到更改文档中特定元素的数据主题的函数.看起来像这样:
I want to map a tap event to a function that changes the data-theme of a specific element in my document. 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?
推荐答案
首先使用.on和vclick而不是委托并点击.您可以在vclick 此处上阅读,在.a 此处
First use .on and vclick instead of delegate and tap.You can read on vclick here, read on .on here
您需要触发刷新事件,然后jquery mobile会再次将样式应用于该元素,例如,如果您更改列表视图,则可以这样做
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
$("#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
这篇关于动态更改JQuery Mobile数据主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!