Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor:event.target.value在mouseenter/mouseleave事件中未定义_Javascript_Meteor_Styles_Mouseenter_Mouseleave - Fatal编程技术网

Javascript Meteor:event.target.value在mouseenter/mouseleave事件中未定义

Javascript Meteor:event.target.value在mouseenter/mouseleave事件中未定义,javascript,meteor,styles,mouseenter,mouseleave,Javascript,Meteor,Styles,Mouseenter,Mouseleave,在我的Meteor应用程序中,我有一个代表一周的表格,每个td元素都有以下结构: <td id="day_hour" style="style" class="class" value="0,4 or 10">text</td> 不起作用。我想这是因为它需要一个助手的值,而且即使我的样式标记在模板中,css也不喜欢这样,因此无法工作。尝试使用传统颜色(如浅绿色或黑色)也不起作用,因此我决定使用事件作为模板 通过使用mouseenter和mouseleave事件,我得到了

在我的Meteor应用程序中,我有一个代表一周的表格,每个td元素都有以下结构:

<td id="day_hour" style="style" class="class" value="0,4 or 10">text</td>
不起作用。我想这是因为它需要一个助手的值,而且即使我的样式标记在模板中,css也不喜欢这样,因此无法工作。尝试使用传统颜色(如浅绿色或黑色)也不起作用,因此我决定使用事件作为模板

通过使用mouseenter和mouseleave事件,我得到了以下代码(注意:我在mouseenter事件中使用黑色来测试颜色的剧烈变化):

正如您所看到的,一旦用户离开td元素,背景色应该恢复到原来的状态。我的问题是:event.currentTarget.value返回未定义的值

因为我第一次认为可能是由于event.currentTarget从一开始就没有定义,所以我使用控制台日志,发现不仅event.currentTarget返回正确的td元素,而且我还可以返回id、样式和类,甚至元素的innerHTML,但不能返回其值,这是返回为未定义的唯一属性

不用说,今天我真的很困惑,特别是因为我还在其他事件(如单击)上使用event.currentTarget.value,并且它在那里工作。我必须补充一点,我还尝试使用jQuery$(event.target).val(),它也返回未定义的


你知道它为什么会这样吗?

你确定
event.currentTarget
td
没有附加根元素处理程序吗?此外,td元素没有value属性,您可以尝试改用data属性。例如
data value=“blah”
。它是td元素,我尝试使用控制台日志。这很奇怪,因为值属性似乎在其他地方起作用。我将尝试数据值。那么如何在事件中获取数据值呢?
event.target.dataset.value
似乎可以工作,谢谢!
<td id="lundi_{{id_heure}}" class="semaine" value={{valeurLundi}} style="background-color:hsla({{valeurLundi}}9, 75%, 55%, 1); border: white solid 5px; text-align:center; color:white;font-weight: bold; cursor:pointer;">
    {{#if lundiIsOk}} ✓ {{else}} {{#if lundiMaybe}} ~ {{else}} ✕ {{/if}} {{/if}}
</td>
.semaine:hover{
    background-color:hsla({{valeurLundi}}9,55%,55%,1);
}
'mouseenter .semaine': function(event){
    event.preventDefault();
    $(event.target).css({"background-color":"black"});
},
'mouseleave .semaine': function(event){
    event.preventDefault();
    if(parseInt(event.currentTarget.value) == 0){
        $(event.target).css({"background-color":"hsl(9, 75%, 55%, 1)"});
    }
    else if(parseInt(event.currentTarget.value) == 4){
        $(event.target).css({"background-color":"hsl(49, 75%, 55%, 1)"});
    }
    else if(parseInt(event.currentTarget.value) == 10){
        $(event.target).css({"background-color":"hsl(109, 75%, 55%, 1)"});
    }
}