Contoh artikel ini memberi tahu kode untuk JS untuk menentukan apakah ada metode. Bagikan untuk referensi Anda.
Kode spesifiknya adalah sebagai berikut:
Salin kode sebagai berikut: <Html>
<head>
<title> JS menentukan apakah ada metode </iteme>
<meta http-equiv = "konten tipe" content = "text /html; charset = utf-8" />
<type skrip = "Teks/JavaScript">
window.onload = function () {
mencoba{
if (test && typeof (test) == "function") {
tes();
}
} catch (e) {
alert ("Metode tidak ada");
}
}
function test () {
alert ("Saya metode test ()");
}
</script>
</head>
<body>
</body>
</html>
Saya harap artikel ini akan membantu pemrograman JavaScript semua orang.