2017-06-21 36 views
0

我有一个使用项目中其他模块的内联模块脚本。 我需要调用使用的onclick从HTML模块功能或其他一切工作..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 

这甚至可能吗?在谷歌上找不到任何东西,我是一个很棒的Google员工。 非常感谢!

回答

0
onClick="myFunction()" 

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

还有对于VanillaJS解决方案...

getElementById('clickable').addEventListener('click', myFunction())