chrome - 从浏览器控制台“未定义”运行 javascript 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22585080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
chrome - run javascript function from browser console "undefined"
提问by
I want to run a javascript function from the browser console,
I'm trying to do it in Chrome (windows 7) and my function is this:
我想从浏览器控制台运行一个 javascript 函数,
我试图在 Chrome (windows 7) 中执行它,我的函数是这样的:
function playVideo() {
var popo = document.getElementsByTagName("object");
for (var i=0; i<popo.length; i++) {
popo[i].playVideo();
}
}
normally this function works fine when I fire it from a webpage
通常,当我从网页中触发它时,此功能可以正常工作
<button onclick="playVideo();">play</button>
or
或者
<a href="javascript:playVideo();">play</a>
but if I paste it into the browser console, and I press Return,
it doesn't work and there is this error:
"undefined"
http://oi57.tinypic.com/z1hjc.jpg
What i'm doing wrong?
但是如果我将它粘贴到浏览器控制台中,然后按回车键,
它就不起作用,并且会出现以下错误:
“未定义”
http://oi57.tinypic.com/z1hjc.jpg
我做错了什么?
采纳答案by user3141004
After paste to console and pressing return you must call this function by name, in you case, after "undefined" write to consle "playVideo()" and press Return.
粘贴到控制台并按回车后,您必须按名称调用此函数,在您的情况下,在“未定义”后写入控制台“playVideo()”并按回车。