我目前正在使用以下 jQuery 插件:jQuery OEmbed。该插件在 FF、Chrome 和 Safari 中运行良好。但是,我在 IE7 中遇到了问题。我已将代码精简为非常简单的代码,但仍然无法弄清楚是什么导致了以下错误:
Error: Object doesn't support this property or method.
错误所指的行是:
$("#container").oembed("http://www.youtube.com/watch?v=nue4pvzuyOo");
这是我的 HTML(同样,非常基本):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery-oembed explicit insert example</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="oe.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$("#container").oembed("http://www.youtube.com/watch?v=nue4pvzuyOo");
});
</script>
<div id="container"></div>
</body>
</html>
可以找到该插件的 javascript here .
有趣的是,这个错误不会出现在 IE8 中——只有 IE7 中。
关于可能导致此错误的原因有什么想法吗?
最佳答案
JSLint报告指出,除其他问题外,您链接到的插件代码在对象文字内有一个额外的逗号。纠正这个问题似乎可以在 IE7 中修复它。
修复:
// Plugin defaults
$.fn.oembed.defaults = {
maxWidth: null,
maxHeight: null,
embedMethod: "replace", // "auto", "append", "fill"
};
更改为:
// Plugin defaults
$.fn.oembed.defaults = {
maxWidth: null,
maxHeight: null,
embedMethod: "replace" // "auto", "append", "fill"
};
注意“replace”后面的逗号
。
关于jQuery OEmbed 插件 - 错误 : Object doesn't support this property or method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1627790/