[英]My external javascript JQUERY doesn't work on chrome or other browser
該html文件是
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>My Website /title>
<link rel='stylesheet' type='text/css' href='stylesheet4.css'>
<link rel='stylesheet' type='text/css' href='http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css'>
</head>
<body>
<!--other code -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="script3.js"></script>
</body>
</html>
我的script3.js文件是
$(function(){
"use strict";
$('#checkOut').click(function(){
var time=2;
alert("The time is "+time+"!");
// more code
});
我如何將其鏈接錯誤? 當我使用jfiddle測試我的代碼時,單擊該按鈕時警報將起作用。 但是,我正在使用記事本++,並且不確定自己在做什么錯。
我看到兩個問題,還有一些應該解決的問題。
在script3.js中,您缺少});
;。 。 所以應該是:
$(function(){
"use strict";
$('#checkOut').click(function(){
var time=2;
alert("The time is "+time+"!");
// more code
});
});
標題標簽的格式不正確:
<title>My Website /title>
需要是:
<title>My Website </title>
編輯:示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>My Website </title>
<link rel='stylesheet' type='text/css' href='stylesheet4.css'>
<link rel='stylesheet' type='text/css' href='http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css'>
</head>
<body>
<!--other code -->
<input type="button" id="checkOut" value="check out" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="script3.js"></script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.