Inline onclick JavaScript variable

后端 未结 3 623
抹茶落季
抹茶落季 2020-12-05 11:33

I have a JavaScript above this html is there any way to pass it inside EditBanner(JS Variable Here) in code below ?

//EditBanner to be changed to pass a Js v         


        
3条回答
  •  孤街浪徒
    2020-12-05 12:10

    There's an entire practice that says it's a bad idea to have inline functions/styles. Taking into account you already have an ID for your button, consider

    JS

    var myvar=15;
    function init(){
        document.getElementById('EditBanner').onclick=function(){EditBanner(myvar);};
    }
    window.onload=init;
    

    HTML

    
    

提交回复
热议问题