簡體   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. 我面臨的挑戰是沒有調用傳遞的 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>

您在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