JavaScript onclickで複数の関数を呼び出すサンプル

環境
Windows 10 home 64bit
Google Chrome 107.0.5304.122

書式
onclick="関数1(); 関数2();"
onclickで複数の関数を呼び出します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<button id="output" onclick="functionA(); functionB();">確認</button>
<script>
function functionA() {
console.log( " AA");
}
function functionB() {
console.log(" BB");
}
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <button id="output" onclick="functionA(); functionB();">確認</button> <script> function functionA() { console.log( " AA"); } function functionB() { console.log(" BB"); } </script> </body> </html>
<!DOCTYPE html>
<html>
<body>

<button id="output" onclick="functionA(); functionB();">確認</button>

<script>
function functionA() {
        console.log( " AA");
}
function functionB() {
        console.log(" BB");
}
</script>

</body>
</html>

実行結果
「確認」ボタンを押すと、コンソールに下記メッセージが表示されます。
AA
BB

JavaScript

Posted by arkgame