はいボタンが押されたときにjQueryダイアログのパラメーターとして関数を呼び出したい。次のコードを使用していますが、これは機能しません。
function showYesNoAlertMsg(divId,optFunction){
//window[optFunction].apply(null, Array.prototype.slice.call(arguments, 2));
$('#'+divId).dialog('open');
$('#'+divId).dialog({
autoOpen: true,
width: 400,
height: 175,
modal: true,
resizable: false,
buttons: {
"Yes": function() {
window[optFunction].apply(null,
Array.prototype.slice.call(arguments, 2));
$(this).dialog("close");
},
"No": function() {
$(this).dialog("close");
}
}
});
}
function newfunc(a,b){
alert(a+'--'+b);
}
<input type="button" name="alert" id="alert"
onclick="showYesNoAlertMsg('boxDivId','newfunc','aaaaa','bbbbb');"/>
<div id="boxDivId">
hello
</div>
「alert」という名前のボタンをクリックすると、この関数showYesNoAlertMsg
が呼び出され、ID「boxDivId」のダイアログボックスが完全に表示されますが、yesボタンで「newFunc」という名前の関数を呼び出したいと思います。この関数をパラメーターとして渡しましたが、ダイアログプロパティで機能していません。の最初のコメント行のコメントをshowYesNoAlertMsg
外すと、この行は正常に機能し、関数「newFunc」を完全に呼び出します。しかし、同じ行が[はい]ボタンで機能していません。教えてください。
ありがとう