<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" type="image/png" href="images/favicon.png">
<title>Jquery alert example</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<link href="http://www.jqueryscript.net/css/jquerysctipttop.css" rel="stylesheet" type="text/css">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container-fluid">
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#event').click(function(){
alert("hello world");
});
});
</script>
<input type='button' id='event' class='btn btn-success' value='click me'>
</div><!--container ends here-->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>
<script src="js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>
<script src="js/wow.min.js"></script>
</body>
</html>
当我点击提醒按钮时,事件无效。我也附加了jQuery文件。如果我从jQuery版本1升级到版本3,jQuery语法需要改变,这是我的另一个疑问。请告诉我我在哪里做错了并指导我如何避免这个问题。
答案 0 :(得分:0)
放置以下script
标记:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#event').click(function(){
alert("hello world");
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
答案 1 :(得分:0)
是的,在你的jquery代码之前把你的jquery库放在顶部。它将起作用,正确的写事件方式是: -
jQuery('#event').on('click', function(){
alert("hello world");
});
答案 2 :(得分:0)
在编写jquery的代码后首先导入基本的.js文件:
$('#btnID').click(function(){
alert('welcome')
});