Javascript 为什么console.log日志记录$(this.data)?

Javascript 为什么console.log日志记录$(this.data)?,javascript,jquery,Javascript,Jquery,为什么我的控制台要记录$this.data?当我将变量记录到控制台日志中时,我得到了未定义的变量 我需要访问chartType才能与代码一起移动: if ($(this).hasClass("points")){ chartType = $(this).data('chart-type'); console.log($(this)); console.log(chartType); } 下面是它的日志 堆栈溢出不允许我将其控制台放在第一行,但它存在 undefi

为什么我的控制台要记录$this.data?当我将变量记录到控制台日志中时,我得到了未定义的变量

我需要访问chartType才能与代码一起移动:

if ($(this).hasClass("points")){
     chartType = $(this).data('chart-type');

     console.log($(this));
     console.log(chartType);
}
下面是它的日志 堆栈溢出不允许我将其控制台放在第一行,但它存在

undefined
可以使用来选择属性

if ($(this).hasClass("points")){
         chartType = $(this).attr('data-custom-value');

         console.log($(this));
         console.log(chartType);
    }

这是在哪里发生的?可能不知道你的意思。但它发生在一个点击功能中。它在控制台中输出未定义的。对不起,如果这不是你需要的。这对我仍然不起作用。这是我的按钮的html。虽然这个代码块可能会回答这个问题,但如果您能提供一点解释,说明为什么会这样做,那将是最好的。谢谢大家…谢谢!我只是想知道,如果有人能解释的话,为什么我的问题会得到负面评价。先谢谢你。杰森