我的代码在HTML内工作,但不是从外部.js文件中工作。外部jQuery问题
在我的外部.js中,我有一个类似于.animate()和hide()等的函数,但它只能用于.text()或.html()这样的函数,但它不能在外部文件中工作。 我甚至删除了我的所有代码,只是保留了这个脚本,仍然没有起作用,但是当我复制粘贴到我的html中时,它工作正常。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body >
<div id="demo"> --- </div>
<button>click me</button>
</body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$("button").click(function(){
$("#demo").html("text");
});
</script>
</html>
与你的代码'$(文件)。就绪包装你的单击事件处理程序(函数(){你的代码});' – Regent 2014-10-17 05:35:09