Javascript HTML按钮onclick事件
这可能是一个非常基本的问题;相信我,我发现在网上很难找到这个问题的答案。我的服务器(Tomcat本地)中存储了3个HTML页面&我想通过单击按钮打开这些HTML页面。任何帮助都将不胜感激 这是我的密码Javascript HTML按钮onclick事件,javascript,html,Javascript,Html,这可能是一个非常基本的问题;相信我,我发现在网上很难找到这个问题的答案。我的服务器(Tomcat本地)中存储了3个HTML页面&我想通过单击按钮打开这些HTML页面。任何帮助都将不胜感激 这是我的密码 <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Online Student Portal</title> &l
<!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>
在线学生门户
选择你的选择。。
此示例将帮助您:
<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')">
在第一个按钮上添加以下内容
onclick="window.location.href='Students.html';"
其他两个按钮也一样
<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';">
试试这个:-
<!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>
在线学生门户
“button”value=“Add Students”onclick=“window.location.href='Students.html';”>
大家都应该知道这是内联脚本,根本不是一个好的实践……因此,对于这类事情,您应该明确使用javascript或jQuery:
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';
});
请参阅注释,还有JSFIDLE中的按钮onclick事件有问题吗
如果是,请参见
窗口。位置
是答案。您可以向我们展示这些按钮的html代码吗?您还没有找到任何向html按钮添加单击处理程序的示例吗?我觉得很难相信。谷歌JavaScript点击窗口位置
Online Student Portal选择你的选择。。谢谢你,阿曼。但这段代码使html在单独的页面中打开。我可以在同一个浏览器窗口中打开它吗?您可以解释更多关于代码段的信息,您添加了哪些详细信息,以及它们是如何解决问题的吗。如果可能,请添加对任何相关文档/阅读材料的参考。谢谢您的帮助!这种方式似乎不喜欢IE8/SharePoint。我们可以使用location.href而不是window.location.hrefforux,这些输入实际上应该是链接,例如。
<!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>
var button_my_button = "#myButton";
$(button_my_button).click(function(){
window.location.href='Students.html';
});
//get a reference to the element
var myBtn = document.getElementById('myButton');
//add event listener
myBtn.addEventListener('click', function(event) {
window.location.href='Students.html';
});