我正在寻找一个非常基本的 html 文档,它显示一个图像(或多个图像),当我点击图像时,它会隐藏图像。我可以使用 jquery 实现这一点。它在 jsfiddle 中工作,但由于某种原因,当我单击桌面上的 html 文档并以这种方式在浏览器中启动它时,它将无法工作。我错过了什么?这是我的 html 文档中的确切代码:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body>
<img id="book" src="C:\Users\user123\Desktop\homeButton.png" alt="" width="100" height="123">
<script>
$(document).ready(function(){
$( "#book" ).click(function( event ) {
event.preventDefault();
$( this ).hide();
});
});
</script>
</body>
</html>
这里是工作 jsfiddle 的链接:
当我在桌面上启动 html 文档时,加载图像需要很长时间(15-20 秒),而当我单击图像时没有任何反应(应该在单击时隐藏图像)。
最佳答案
本地文档没有协议(protocol),所以你需要为 jQuery 提供一个:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
关于javascript - 在桌面 HTML 文档上运行 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25061819/