如何將字串轉換為 JavaScript 函式呼叫?


要將字串轉換為 JavaScript 函式呼叫,請嘗試執行以下程式碼

範例

即時範例

<html>
   <body>
      <script>
         function myFunction(argument) {
            alert('My function ' + argument);
         }
         functionName = 'myFunction';
         window[functionName]('is working.');
      </script>
   </body>
</html>

更新於: 03-10-2019

418 次瀏覽

開啟你的 職業生涯

完成該課程即可獲取認證

開始
廣告
© . All rights reserved.