私はjavascriptを初めて使用しますが、次のような文字列で表される関数を呼び出すことができることを知っています:
var function_to_call = window[values['function']];
//Where values['function']='functionName'
これまでのところ順調ですが、次のようになります。
if(typeof function_to_call == 'function'){
if(values['parameters']!= '')
function_to_call(values['parameters']);
else function_to_call();
};
もちろん、これは機能しません。パラメーターが「parameter1、parameter2」としてすべて 1 つの文字列で出力されるため、最終的には次のようになります。
function_to_call("parameter1, parameter2");
それよりも
function_to_call(parameter1, parameter2);
何か案は?あなたの時間を大切にしてください!
拡張:
関数に渡されるパラメーターは、ページ内の要素の「id」を表します。したがって、呼び出される関数は、次のようにしてこれらの要素を取得しようとします。
document.getElementById(parameter1);
...some other things...
document.getElementById(parameter2);