J'ai 3 boutons - btn 1, 2 et 3 - avec chacun leur propre fonction qui lui est assignée. Ce que je veux, c'est que le bouton 1 ait la fonction 1 par défaut. Mais en appuyant sur le bouton 2, la fonction du bouton 1 doit passer à la fonction 4. En appuyant sur le bouton 3, le bouton 1 doit être de nouveau assigné à la fonction 1. Ainsi, les boutons 2 et 3 ont leur propre fonction, mais ils ont aussi de changer la fonction du bouton 1. Le code est:fonctions de liaison et de désengagement
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button id="button1">button 1</button>
<button id="button2">button 2</button>
<button id="button3">button 3</button>
<script>
document.getElementById("button1").addEventListener("click", myFunction1);
function myFunction1() {
alert ("1");
}
document.getElementById("button2").addEventListener("click", myFunction2);
function myFunction2() {
alert ("2");
}
document.getElementById("button3").addEventListener("click", myFunction3);
function myFunction3() {
alert ("3");
}
</script>
<script>
function myFunction4() {
alert ("4");
}
</script>
</body>
</html>
Pourquoi jQuery est-il étiqueté lorsqu'il n'y a pas de jQuery? – rottenoats