Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/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
Elm使用Html.attribute和;onmouseover“;不起作用_Elm - Fatal编程技术网

Elm使用Html.attribute和;onmouseover“;不起作用

Elm使用Html.attribute和;onmouseover“;不起作用,elm,Elm,我想添加onmouseover来更改按钮的背景色。 我不需要使用Html.Events.onMouseOver,因为这是一项非常简单的任务。我不想使用其他外部库 我使用创建Html.attribute div [ -- Html.Event.onMouserOver NoUse Html.attribute "onmouseover" "$(this).css('background','green');" ] [ ... ] 当我向Elm添加未知属性时。Elm在属性中添加“数据

我想添加onmouseover来更改按钮的背景色。 我不需要使用Html.Events.onMouseOver,因为这是一项非常简单的任务。我不想使用其他外部库

我使用创建Html.attribute

div
[
   -- Html.Event.onMouserOver NoUse
   Html.attribute "onmouseover"  "$(this).css('background','green');"
]
[ ... ]
当我向Elm添加未知属性时。Elm在属性中添加“数据-”前缀 因此,当我编译代码时,它将被翻译成Html

<div data-onmouseover="$(this).css('background','green');">...</div>
。。。
所以“onmouseover”不起作用

我怎样才能破解Elm的“鼠标悬停”事件? 及
为什么Elm需要阻止这样的事件?

Elm故意这样做是为了避免脚本注入攻击(例如:如果你从用户那里获取一个字符串并将其作为此处的值,他们就不能编写一些恶意JS并让你的页面执行)

正确的解决方案是使用和Elm代码(如果确实需要任意JS,则包括端口)。你说你不需要使用它,但在Elm你需要

即使你可以做你想做的事情,它也不能按你想的方式工作:Elm控制页面的DOM,并且可能破坏和重新创建元素,这意味着你在JS中所做的更改可能会被任意丢失