2017-06-21 13 views
0

プロジェクトの他のモジュールを使用してインラインモジュールスクリプトを取得しました。 私はJSモジュールとhtml間の通信

<script type="module"> 
    import * as blabla from './somemodule.js'; 

    function myfunction(){ 
     console.log("Youhou!"); 
    } 

    //Communication from script to html works fine 
    document.getElementById('test').onclick = myfunction; 
</script> 
<button id="test">Test</button> 
<button onclick="myfunction();">Test</button>//This dont work 

も可能。この..ですonclickを使用したり、他のすべての作業のhtmlからモジュールの関数を呼び出す必要がありますか? Googleで何かを見つけたら、私はいいgooglerです。 ありがとうございます!

答えて

0
onClick="myFunction()" 

または

jQuery('#clickable').click(myFunction()); 

そのためVanillaJSソリューションもあり...

getElementById('clickable').addEventListener('click', myFunction()) 
関連する問題