调用webcam的capture()函数,然后报TypeError: webcam.capture is not a function(…),完全不明白为啥,以下是代码(官方Demo,几乎没有修改),求大神指点!<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery-webcam-master</title>
<link href="cs.css" rel="stylesheet" type="text/css">
<script src="http://www.jq22.com/jquery/1.11.1/jquery.min.js"></script>
<script src="jquery.webcam.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
jQuery("#webcam").webcam({
    width: 320,
    height: 240,
    mode: "callback",
    swffile: "jscam_canvas_only.swf", // canvas only doesn't implement a jpeg encoder, so the file is much smaller
    onTick: function(remain) {
        if (0 == remain) {
            jQuery("#status").text("Cheese!");
        } else {
            jQuery("#status").text(remain + " seconds remaining...");
        }
    },
    onSave: function(data) {
        var col = data.split(";");
    },
    onCapture: function () {
        webcam.save();
    },
    debug: function (type, string) { },
    onLoad: function () {
    // Page load
        var cams = webcam.getCameraList();
        for(var i in cams) {
            jQuery("#cams").append("<li>" + cams[i] + "</li>");
        }
    }
});
});
</script>
</head>
<body>
<div id="webcam"></div>
<input type="button" value="Capture" onclick="webcam.capture()" />
</body>
</html>

解决方案 »

  1.   

    jquery.webcam.min.js你引对了吗?定义在这个文件中
    使用浏览器开发者工具查看这个js是否404还是200或304
      

  2.   


    发布网站通过http协议访问,而且确保你的swf没有被浏览器禁用,默认flash不是最新版本是被浏览器禁用的,需要人工点击允许运行后,刷新页面才会注册capture这个方法var source = '<object id="XwebcamXobjectX" type="application/x-shockwave-flash" data="'+webcam["swffile"]+'" width="'+webcam["width"]+'" height="'+webcam["height"]+'"><param name="movie" value="'+webcam["swffile"]+'" /><param name="FlashVars" value="mode='+webcam["mode"]+'&amp;quality='+webcam["quality"]+'" /><param name="allowScriptAccess" value="always" /></object>'; if (null !== webcam["extern"]) {
        $(webcam["extern"])[webcam["append"] ? "append" : "html"](source);
    } else {
        this[webcam["append"] ? "append" : "html"](source);
    } var run = 3;
    (_register = function() {
        var cam = document.getElementById('XwebcamXobjectX');     if (cam && cam["capture"] !== undefined) { /* Simple callback methods are not allowed :-/ */
    webcam["capture"] = function(x) {
        try {
    return cam["capture"](x);
        } catch(e) {}
    }
    推荐学习资料
    jquery全年日期选择器日历插件
    jquery attr prop 区别
      

  3.   

    Jquery.Webcam 运行不能通过文件打开,要通过http协议打开就可以运行了,还有留意swf文件路径有没有错,路径出错也会导致这个问题
      

  4.   

    webcam.capture()改为
    document.getElementById('XwebcamXobjectX').capture();
    document.getElementById('XwebcamXobjectX').save();
    就不报错了
      

  5.   

    改成webcam.capture()改为
    document.getElementById('XwebcamXobjectX').capture();
    document.getElementById('XwebcamXobjectX').save();还是会报错
      

  6.   

    需要放到项目里,用tomcat 跑起来,访问方式IP:端口   这样就不会报错了