簡體   English   中英

如果HTML中包含JS函數,如何在瀏覽器控制台中使用所有JS函數?

[英]How can I all a JS function in a browser console if the JS function is included in the HTML?

HTML:

<script type="text/javascript" src="scripts/js/script.js"></script>

jQuery函數在這里:

$(document).ready(function() {
   function rnmtn(){
      console.log("red");
   }
});

我怎樣才能調用rnmtn(); 在控制台中,它不會返回undefined -腳本未鏈接到html對象-我需要它自行運行。

發揮作用

function rnmtn(){
  console.log("red");
} 

並在控制台中輸入以下內容進行調用

rnmtn()

您需要使該功能在窗口范圍內可訪問,

$(document).ready(function() {
   window.rnmtn = function rnmtn(){
      console.log("red");
   }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM