Jquery does not run [closed]

-2

I'm trying to put a jquery code inside the script tag but nothing happens:

<!DOCTYPE html>
    <html>
    <head>
    	<title>Pruebas Javascript</title>
    	
    </head>
    <body>
	
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
	<script type="text/javascript" scr="https://code.jquery.com/jquery-latest.min.js"></script>

     <div align="center">  
      <h1>Formulario</h1>
    	<form class="form-horizontal">	
    			Escribe tu nombre : <input id ="nombre" type="text"  name="nombre" > <br><br>
    			Escribe tus apellidos : <input id ="apellidos" type="text" name="apellidos"><br><br>
    			Escribe tu edad : <input id ="edad" type="text" name="edad"><br><br>
    			<input type="button" id ="boton" name="boton" value = 'Aceptar' class="btn btn-primary" onclick="mostrar()">
    	</form>
      </div>
    
      <script type="text/javascript">
    
        		$("#boton").click( function(){
        			alert("nada");
        		});
    	</script>
    </body>
    </html>
    
asked by Ruben 18.07.2017 в 13:55
source

3 answers

-1

In the script tag you have scr when it should be src :

<!DOCTYPE html>
    <html>
    <head>
    	<title>Pruebas Javascript</title>
    	
    </head>
    <body>
	
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
	<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>

     <div align="center">  
      <h1>Formulario</h1>
    	<form class="form-horizontal">	
    			Escribe tu nombre : <input id ="nombre" type="text"  name="nombre" > <br><br>
    			Escribe tus apellidos : <input id ="apellidos" type="text" name="apellidos"><br><br>
    			Escribe tu edad : <input id ="edad" type="text" name="edad"><br><br>
    			<input type="button" id ="boton" name="boton" value = 'Aceptar' class="btn btn-primary" >
    	</form>
      </div>
    
      <script type="text/javascript">
    
        		$("#boton").click( function(){
        			alert("nada");
        		});
    	</script>
    </body>
    </html>
    
answered by 18.07.2017 / 14:08
source
0

The problem is that in the onclick you call the function show () that does not exist.

<input onclick=type="button" id ="boton" name="boton" value = 'Aceptar' class="btn btn-primary" onclick="mostrar()">

the show () function is not defined To fix it you should define it in the following way:

$("#boton").click( function mostrar(){
            alert("nada");
        });
    
answered by 18.07.2017 в 14:07
0

I can think of 3 solutions:

1- Change $("#boton").click( function(){ by $("#boton").click(function(e){

2- Put the Jquery functions inside this code:

jQuery(function ($) {
      Poner tu codigo aqui
});

3-You should remove the call onclick="mostrar()" For 2 reasons:

  • You can be over writing the " Onclick " function
  • Surely if you right click on the web page that runs your code and put "inspect" you will see a red button with a cross,
    if you click on that button it will show you that you have an error
    javascript, the error in theory is that the " mostrar() " function does not
    exists in your code, then as you can not find it click any javascript / jquery code that you have and the rest is not executed (although this well coded)

If it does not help to warn me and we see other options.

Greetings!

    
answered by 18.07.2017 в 14:05