「なでしこv3」開発掲示板

なでしこ3を改善するための掲示板

(#330) 返信ありがとうございます - おさね (2024-10-05 22:57) /低 未処理
以下のJavaScriptが正常に動作するように、なでしこの関数内関数からも、外側の変数にアクセスできればより便利になるのにな、と思った次第です。
恐らく大きく修正が必要なのではないかと思いますので、またゆっくりご検討ください。

ーーーーー

click_button.addEventListener("click", ()=>{
  const ok_button=document.body.appendChild(document.createElement("button"));
  ok_button.textContent="OK";
  const cancel_button=document.body.appendChild(document.createElement("button"));
  cancel_button.textContent="cancel";

  ok_button.addEventListener("click", ()=>{
    document.body.removeChild(ok_button);  //外側の関数内で宣言した変数も使える
    document.body.removeChild(cancel_button);
  });
  cancel_button.addEventListener("click", ()=>{
    document.body.removeChild(ok_button);
    document.body.removeChild(cancel_button);
  });
});
編集
📌 変数のスコープってどうなっているんでし.. / おさね (2024-08-27 15:48) (#322) /低 未処理
└─ 遅くなりました / クジラ飛行机 (2024-09-06 23:16) (#323) /低 未処理
└─ 返信ありがとうございます / おさね (2024-10-05 22:57) (#330) /低 未処理
└─ 解決済み / クジラ飛行机 (2026-08-12 14:02) (#432) /低 解決

✏️ (#330)へ返信する

編集時に使うキーを入力(省略可能)

画像ファイル(最大300KB)を添付可能