divに関数を動的にアタッチし、イベントも渡す必要があります。FireFox - 動的に追加された機能にイベントを添付しますか?
Chrome/IEでは動作しますが、FireFoxでは動作しません。私はFireFoxのコンソールで次のエラーを取得しています
:にReferenceError:イベントは
が定義されていないがこれはどのように解決することができますか?
CodePen:https://codepen.io/dsomekh/pen/YrKmaR
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
.example{
cursor:pointer;
border:1px solid black;
text-align:center;
}
</style>
<script>
window.onload = function() {
var div = $(".example");
div.click(function() {Test(event);});
}
function Test (event)
{
alert(event);
}
</script>
<html>
<div class="example">When clicking on this div, you should get an alert with the event details. This does not work in FireFox.</div>
</html>
これは、動的な要素とは何の関係もないのだが、Firefoxは世界をサポートしていないためだけで起こりますイベントオブジェクト。 – adeneo