使用jQuery Mobile在点击时更改数据图标 [英] Change data-icon on click with jquery mobile

查看:65
本文介绍了使用jQuery Mobile在点击时更改数据图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

function togglePOIAndDisplay(toggle){
    var display = $(toggle).attr('data-icon');
    console.log(display);
    if(display == 'minus'){
        $(toggle).attr('data-icon', 'check');
            console.log(display);
    } else {
        $(toggle).attr('data-icon', 'minus');
        removeMarkers(toggle);
    }
}   

它将把minus登录到控制台并进入第一个if()块并正确执行displayAllPOIOfType(),但尽管设置正确,它也不会反映值的变化.任何想法为何会这样,因为它显然可以正确读取/设置属性.

It will log minus to the console and go into the first if() block and executes displayAllPOIOfType() correctly, but it will not reflect the change of the value although it gets set correctly. Any ideas why that is, because it obviously reads/sets the attribute correctly.

是否有我需要致电的更新function?谢谢

Is there an update function I need to call? thanks

推荐答案

这取决于它是按钮,选择还是接受data-icon属性的其他东西.不幸的是,jQuery Mobile对动态更改由data-*属性控制的事物没有很好的支持,因此您必须调整属性以及修改子元素上的类.

This depends on whether it's a button, or a select, or some other thing that accepts the data-icon attribute. Unfortunately, jQuery Mobile doesn't have great support for dynamically changing things controlled by data-* attributes, so you'll have to adjust the attribute as well as modify the classes on the child elements.

对于按钮,应该可以执行以下操作:

For buttons, something like this ought to work:

$(buttonSelector).attr('data-icon', newIcon);
                 .find('.ui-icon')
                     .addClass('ui-icon-' + newIcon)
                     .removeClass('ui-icon-' + oldIcon);

这篇关于使用jQuery Mobile在点击时更改数据图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆