我目前正在尝试使用photobooth.js制作一个简单的照相亭页面。我对JS和网页了解甚少,但这似乎是我所想到的最佳解决方案。我的问题是,当我加载脚本(根据网站,没有依赖项)并尝试在我的基本应用程序中使用它时,什么也没发生,所以很明显,我没有正确调用脚本。为了确保脚本已加载,我在ShowAlert()
语句中为photobooth.js
添加了onload="ShowAlert()"
函数,该函数的确触发了警报。
因此,在页面上添加myPhotobooth = new Photobooth( document.getElementById( "container" ) );
不能作为advertised here使用(或更可能是我不知道如何使用它)
有人可以解释一下我所缺少的吗?
修改后的photobooth_min.js
源:
/**
*
* Photobooth.js version 0.7
*CUSTOM DEBUG CODE
*/
function ShowAlert() {
alert('show this message');
}
/**
*Rest of photobooth_min.js code, unmodified.
*/
我的
index.html
页面:<!DOCTYPE html>
<html>
<head>
<title>photobooth</title>
</head>
<body>
<div id="example"></div>
<script type="text/javascript" src="photobooth_min.js" onload="ShowAlert()"></script>
<script>
myPhotobooth = new Photobooth( document.getElementById( "example" ) );
</script>
</body>
</html>
我的目录结构:
最佳答案
调用外部脚本文件时,内部不应有任何内容...
<script type="text/javascript" src="WebContent/photobooth_min.js"></script>
<script>
var myPhotobooth = new Photobooth( document.getElementById( "example" ) );
</script>
另一件事是文件的
path
,在这种情况下,假设您在名为index.html
的文件中包含此HTML,则要设置的结构是:|--- index.html
|--- WebContent (folder)
|--- photobooth_min.js
首先,将它们都放在同一个文件夹中,例如:
|-- index.html
|-- photobooth_min.js
并仅以
<script type="text/javascript" src="photobooth_min.js"></script>
附言请记住,
photobooth
脚本将永远无法在IE和Safari上运行...在Windows和Mac平台上,这两种最常用的浏览器...关于javascript - 如何正确调用photobooth.js,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27836623/