排名编程语言Ratings同比上月
1C11.83%-4.12%
2Python11.67%+1.20%
3Java11.12%-2.37%
4C++7.13%+0.01%
5C#5.78%+1.20%
6Visual Basic4.62%+0.50%
7JavaScript2.55%+0.01%
8Assembly language2.42%+1.12%
9PHP1.85%-0.64%
10SQL1.80%+0.04%
11Classic Visual Basic1.52%+0.77%
12Groovy1.46%+0.48%
13Ruby1.27%+0.03%
14Go1.13%-0.33%
15Swift1.07%-0.31%
16MATLAB1.02%-0.07%
17Fortran1.01%+0.65%
18R0.98%-1.40%
19Perl0.78%-0.53%
20Delphi/Object Pascal0.77%+0.24%

  • 获取某个dom的所有data-*开头的属性?
    '''

//方法一
$("#id").data();
//方法二
jQuery.data($('#id')); //该函数传入的参数为dom
'''

假设我们有个需求是, 当选择到某个选项时, 弹出确认框提示.用户选择是,那么值就改变, 如果选择否, 那么我们需要还原为上次的选择.实现如下:(相比使用全局变量,我们可以用$.data来优雅处理)

$('select').change(function() {
    let selected = $(this).val();
    if (selected == 'beer') {
        if (!confirm('Are you sure?')) {
            $(this).val($.data(this, 'current'));
            return false;
        }     
    }
    $.data(this, 'current', $(this).val());
});

排名编程语言Ratings同比上月
1C12.57%-4.41%
2Python11.86%+2.17%
3Java10.43%-4.00%
4C++7.36%+0.52%
5C#5.14%+0.46%
6Visual Basic4.67%+0.01%
7JavaScript2.95%+0.07%
8PHP2.19%-0.05%
9Assembly language2.03%+0.99%
10SQL1.47%+0.02%
11Groovy1.36%+0.59%
12Classic Visual Basic1.23%+0.41%
13Fortran1.14%+0.83%
14R1.05%-1.75%
15Ruby1.01%-0.03%
16Swift0.98%-0.44%
17MATLAB0.98%+0.11%
18Go0.90%-0.52%
19Prolog0.80%+0.41%
20Perl0.78%-0.33%