Using data attributes with jQuery

后端 未结 4 1926
我寻月下人不归
我寻月下人不归 2020-12-03 03:19

I have this button:

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 03:40

    I think data will look on lowercases: alert($(this).data("themevalue")) //grid

    or if you want to use themeValue you need to use:

    edit:

    I was wrong, it doesnt have anything to do with lowercases, you can use themeValue if you are having the attribute: data-theme-value then you call itwith $(element).data("themeValue")

    
    
    $(".themeChanger").click(function() {
        var el = $(this);
    
        alert($(this).data("themeValue")); //Theme2
        alert($(this).data("themevalue")); //Theme1
    });
    

提交回复
热议问题