Bonjour à tous, cela pourrait être une question très fondamentale, croyez-moi, j'ai trouvé très difficile de trouver la réponse à cette question sur internet. J'ai 3 pages html stockées dans mon serveur (tomcat localement) et je veux ouvrir ces htmls sur le clic de bouton. Toute aide serait très appréciée. Thankx guys
Voici mon code …
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Online Student Portal</title> </head> <body> <form action=""> <h2>Select Your Choice..</h2> <input type="button" value="Add Students"> <input type="button" value="Add Courses"> <input type="button" value="Student Payments"> </form> </body> </html>
Essaye ça:-
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Online Student Portal</title> </head> <body> <form action=""> <input type="button" value="Add Students" onclick="window.location.href='Students.html';"/> <input type="button" value="Add Courses" onclick="window.location.href='Courses.html';"/> <input type="button" value="Student Payments" onclick="window.location.href='Payment.html';"/> </form> </body> </html>
Vous devriez tous savoir que ceci est un script en ligne et n'est pas une bonne pratique … avec cela dit, vous devriez utiliser définitivement javascript ou jQuery pour ce type de chose:
HTML
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Online Student Portal</title> </head> <body> <form action=""> <input type="button" id="myButton" value="Add"/> </form> </body> </html>
JQuery
var button_my_button = "#myButton"; $(button_my_button).click(function(){ window.location.href='Students.html'; });
Javascript
//get a reference to the element var myBtn = document.getElementById('myButton'); //add event listener myBtn.addEventListener('click', function(event) { window.location.href='Students.html'; });
Voir les commentaires pourquoi éviter les scripts en ligne et aussi pourquoi les scripts en ligne sont mauvais
Sur le premier bouton, ajoutez ce qui suit.
onclick="window.location.href='Students.html';"
De même, faites les 2 boutons restants.
<input type="button" value="Add Students" onclick="window.location.href='Students.html';"> <input type="button" value="Add Courses" onclick="window.location.href='Courses.html';"> <input type="button" value="Student Payments" onclick="window.location.href='Payments.html';">
Vous avez des problèmes avec un événement button onclick dans jsfiddle?
Si tel est le cas, voir l' événement Onclick sans tirer sur jsfiddle.net
Cet exemple vous aidera:
<form> <input type="button" value="Open Window" onclick="window.open('http://www.google.com')"> </form>
Vous pouvez ouvrir la page suivante sur la même page en:
<input type="button" value="Open Window" onclick="window.open('http://www.google.com','_self')">
<body> "button" value="Add Students" onclick="window.location.href='Students.html';"> <input type="button" value="Add Courses" onclick="window.location.href='Courses.html';"> <input type="button" value="Student Payments" onclick="window.location.href='Payments.html';"> </body>