jQuery在Eclipse中不起作用 [英] jQuery Not Working in Eclipse

查看:65
本文介绍了jQuery在Eclipse中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery还是有点新,所以我可能犯了一个基本错误. 我刚刚完成了jQuery入门课程,现在尝试做一些自己的基本工作,但是遇到了一些小障碍. 从本质上讲,似乎没有正确调用jQuery文件script.js. 当我将其插入到stackoverflow中时,它似乎工作正常.然而, 当我在浏览器中提取html文件时,它仅显示文件中的html元素,而不显示任何jQuery代码.

Still a bit new with jQuery so I may be making a basic error. I just completed the jQuery introductory course and now am trying to do some of my own basic work, but have hit a slight road block. Essentially it seems the jQuery file script.js isn't getting called properly. When I ran it inserting it into stackoverflow it seems to work fine. However, when I pull the html file in the browser it only displays the html elements in the file and not any of the jQuery code.

任何帮助将不胜感激!

	$(document).ready(function() {
	    $("body").append("<p>I\'m a paragraph!</p>");
			/* write 'Hello World! to the first div' */
			$("#first").append('<h1> Hello World!</h1>');

			//a clickable 'Hello World!' example
			$("#link").click(function() {
				$('#greeting').append("<h1>Hello Again!</h1>");
			});
		});

<!DOCTYPE html>
<html>
<head>
<title>Hello World - jQuery Style</title>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
</head>
<body>
	<div id="first"></div>
	<div id="second">
		<a href="#" id="link">Click Me!</a> <br /> <span id="greeting"></span>
	</div>
</body>
</html>

推荐答案

获取jquery.min.js后,您应该声明当前的javascript文件

You should declare your current javascript file after you get the jquery.min.js

如果您在控制台中查看(右键单击并检查),您会注意到它无法理解$ jquery符号.

If you look in your console ( right click and inspect ) You will notice that it cannot understand $ jquery sign.

解决方案应该只是在html中交换这两行:

Solution should be just swap these two lines in your html :

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>

这篇关于jQuery在Eclipse中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆