繁体   English   中英

jQuery仅适用于.html文件,而不适用于.PHP文件?

[英]jQuery only works in .html file and it doesn't work in .PHP file?

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

这很好。 但是,当我将文件的扩展名从.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文件中却不能工作?

没有<body> (打开标签)。 并两次包含jQuery

只需替换:

<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文件扩展名也可以正常工作。

请检查

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM