Como lidar com eventos de Botão Clique em jQuery?
Preciso de um botão e lidar com o evento em jQuery. E estou a escrever este código, mas não está a funcionar. Perdi alguma coisa?
<!-- Begin Button -->
<div class="demo">
<br> <br> <br>
<input id = "btnSubmit" type="submit" value="Release"/>
<br> <br> <br>
</div>
<!-- End Button -->
e no ficheiro javascript
function btnClick()
{
// button click
$("#btnSubmit").button().click(function(){
alert("button");
});
}
97
Author: Ahmad Farid, 2010-12-01
9 answers
Você tem que colocar o manipulador de eventos no $(documento).Evento Pronto:
$(document).ready(function() {
$("#btnSubmit").click(function(){
alert("button");
});
});
192
Author: Davide Gualano, 2010-12-01 11:31:47
$(document).ready(function(){
$('your selector').bind("click",function(){
// your statements;
});
// you can use the above or the one shown below
$('your selector').click(function(e){
e.preventDefault();
// your statements;
});
});
20
Author: Lawrence Gandhar, 2014-07-28 14:25:07
$("#btnSubmit").click(function(){
alert("button");
});
6
Author: Ali Tarhini, 2010-12-01 11:31:47
$('#btnSubmit').click(function(){
alert("button");
});
Ou
//Use this code if button is appended in the DOM
$(document).on('click','#btnSubmit',function(){
alert("button");
});
Ver documentação para mais informações:
https://api.jquery.com/click/
5
Author: Bruce Phillip Perez, 2017-05-25 10:17:27
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#button").click(function(){
alert("Hello");
});
});
</script>
<input type="button" id="button" value="Click me">
3
Author: Nivediny, 2014-05-27 07:11:09
<script type="text/javascript">
$(document).ready(function() {
$("#Button1").click(function() {
alert("hello");
});
}
);
</script>
1
Author: Anup Ghanshala, 2013-02-14 05:49:00
$('#btnSubmit').click(function(event){
alert("Button Clicked");
});
Ou como está a usar o botão enviar para que possa escrever o seu código no evento de validação do formulário como
$('#myForm').validate(function(){
alert("Hello World!!");
});
1
Author: Hiren, 2014-07-28 14:26:16
Funciona para mim
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$("#btn").click(function() {
alert("email")
});
</script>
0
Author: navyad, 2013-10-09 17:03:03
Tenta Isto:
$(document).on('click', '#btnClick', function(){
alert("button is clicked");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnClick">Click me</button>
0
Author: Rafiqul Islam, 2018-09-03 14:40:13