简体   繁体   English

Function 作为未调用的参数传递

[英]Function passed as parameter not being called

I have a button that when clicked receives a function passed as an argument and the passed function is also an argument to another function created using JavaScript. I have a button that when clicked receives a function passed as an argument and the passed function is also an argument to another function created using JavaScript. The challenge I have is that the passed function is not being invoked.我面临的挑战是没有调用传递的 function 。

 function alerts(x) { document.getElementById('dialogfoot').innerHTML = '<button onclick="submit(\'' + x + '\')">Yes</button>'; } function submit(x) { x(); } function callthis() { alert('welcome call me'); }
 <button onclick="alerts(callthis)">submit</button> <div id="dialogfoot" style=""></div>

You are passing the string 'callthis' in submit1 rather than the function callthis .您在submit1中传递字符串'callthis'而不是 function callthis

 function alerts(x){ document.getElementById('dialogfoot').innerHTML='<button onclick="submit1('+x+')">Yes</button>'; } function submit1(x){ x(); } function callthis(){ alert('welcome call me'); }
 <button onclick="alerts(callthis)" id='btn'>submit</button> <div id="dialogfoot" style=""></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM