My code is like below:
function OnApply(runFunc) { $("#myCfmModal").modal('show'); $("#myCfmModal").find("#myCfmModalText").html("Apply change now?"); $("#myCfmModal").find("#myCfmModalHeader").css("background","#cccccc"); $("#myCfmModal").one('click', '#okbtn', runFunc); } function cool() { alert("cool!"); } I have a problem running the code above. I call the OnApply(cool()) as below:
<button class="btn btn-success" onclick="OnApply(cool())">Apply</button> OnApply(cool()) will show a modal box and run a function cool(). What I want to do is to run function cool() when I click the OK button in the modal box. However the cool() function will always run first before I click the OK button. Any idea what went wrong?
OnApply()?OnApply(cool), or the returned value of the function,OnApply(cool())? The latter will cause this issue, as you should be using the first method.