“Button JavaScript OnClick” Kod odpowiedzi

Button JavaScript OnClick

document.getElementById("myBtn").addEventListener("click", function() {
  alert("Hello World!");
});
Batman

Jak dodać wydarzenie OnClick w JavaScript

var element = document.getElementById("elem");
element.onclick = function(event) {
  console.log(event);
}
TC5550

Uruchom funkcję, gdy przycisk ma onClick

<script>
function myFunction() {
  alert("ALERT THIS FUNCTION HAS RUNNED");
}
</script>
<button onclick="myFunction">click to run function</button>
Lava

Button JavaScript OnClick

// Here you can use getElementById 
// or getElementByClassName or getElementByTagName...
// Example #1
document.getElementById("button").onclick = function() {
	alert("Hello World!");
}

// Example #2
let obj = document.getElementsByClassName('button');
obj.addEventListener("click", function() {
    // your code here...
});

// Example #3 (getting attributes)
let obj = document.getElementById("button")
obj.onclick = function() {
  	obj.style.display = "none";
	// or:
  	// obj.style = "display: none; color: #fff"
}
Modern Marten

przycisk JavaScript

<button onclick="Function()">Text</button>
Defeated Dugong

JavaScript onClick

 document.getElementById("Save").onclick = function ()
    {
     alert("hello");
     //validation code to see State field is mandatory.  
    }
rabbit.sol

Odpowiedzi podobne do “Button JavaScript OnClick”

Pytania podobne do “Button JavaScript OnClick”

Więcej pokrewnych odpowiedzi na “Button JavaScript OnClick” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu