複数のスクリプトで共有する変数及び関数を定義する
概要
複数のクライアントスクリプトで変数及び関数をする手順です。
onLoadスクリプト:グルーバル変数の宣言
共有する変数及び関数をOnLoadで宣言します。
onLoadスクリプトの「Isolate script」を無効にします。
var globalVar = "初期値"; // 共有変数
function onLoad() {
}
function sayHi(name) { // 共有関数
alert('Hi ' + name);
}
フィールド1のonChangeスクリプト:共有変数の値を変更
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
globalVar = "フィールド1で変更。"; //共有変数の値を変更
}
フィールド2のonChangeスクリプト:グローバル変数を表示
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert('変数の値:' + globalVar); //共有変数の値を表示
sayHi('Hitoshi'); //共有関数の呼び出し
}
実行結果
Author And Source
この問題について(複数のスクリプトで共有する変数及び関数を定義する), 我々は、より多くの情報をここで見つけました https://qiita.com/htshozawa/items/ac50f96fc09d893e2746著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .