Подтвердить что ты не робот

Кнопка HTML onclick

3 buttons 3 onclick events

Привет всем, это может быть очень простой вопрос, поверьте, мне очень трудно найти ответ на этот вопрос в Интернете. У меня есть 3 html-страницы, хранящиеся на моем сервере (tomcat локально), и я хочу открыть эти htmls при нажатии кнопки. Любая помощь будет высоко оценен. Друзья благодарения

вот мой код...

<!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>
4b9b3361

Ответ 1

Попробуйте следующее: -

<!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>

Ответ 2

Вы все должны знать, что это встроенный скриптинг и не является хорошей практикой... с тем, что вы должны окончательно использовать javascript или jQuery для этого типа вещей:

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';
  });

Смотрите комментарии почему избегайте встроенных скриптов, а также почему встроенные скрипты плохи

Ответ 3

на первой кнопке добавьте следующее.

onclick="window.location.href='Students.html';"

аналогично делают остальные 2 кнопки.

<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';">

Ответ 4

Этот пример поможет вам:

<form>
    <input type="button" value="Open Window" onclick="window.open('http://www.google.com')">
</form>

Вы можете открыть следующую страницу на той же странице:

<input type="button" value="Open Window" onclick="window.open('http://www.google.com','_self')">

Ответ 6

<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>