![](/img/trans.png)
[英]Javascript. How to check if a false boolean parameter is passed in a function?
[英]How to check the type of a parameter passed to a function in JavaScript?
我想確保傳遞給 function 的參數是一個元素,而不是數字或字符串,所以我的程序不會崩潰?
function myFunction(element){
console.log(element.style.color)
}
也許您正在尋找HTMLElement :
function myFunction(element) {
if (element instanceof HTMLElement) {
console.log(element.style.color)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.