jQuery只适用于.html文件,它在.PHP文件中不起作用?

时间:2013-10-03 12:49:16

标签: javascript php jquery html

我有一个HTML文件,里面有一个简单的jQuery高亮效果。

这很好用。但是当我将文件的扩展名从.html更改为.php并将其上传到我的服务器时,它就无法正常工作。

它不起作用我的意思是它没有突出显示Div。

以下是代码:

<!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">
<style>
div {
width: 100px;
height: 100px;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="hflip.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="counter"></div>
<form>
<input name="ajaxlink" type="button" id="ajaxlink" class="ajaxlink" />
</form>
<script>
$( '#ajaxlink' ).click(function() {
$( "#counter" ).effect( "highlight", "slow" );
});
</script>
</body>
</html>
我做错了什么?为什么它在HTML文件中工作正常而且它不在.PHP文件中?

3 个答案:

答案 0 :(得分:1)

没有<body>(开放标签)。并且两次包含jquery

答案 1 :(得分:0)

只需替换:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

并删除最后一个脚本包含

也可以正常使用PHP文件扩展名。

请检查

答案 2 :(得分:0)

删除此脚本并运行代码.. :))

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>