chrome - 从浏览器控制台运行javascript函数“undefined” [英] chrome - run javascript function from browser console "undefined"

查看:1270
本文介绍了chrome - 从浏览器控制台运行javascript函数“undefined”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从浏览器控制台运行javascript函数,

我想在Chrome(Windows 7)中执行此操作,我的功能是:

  function playVideo(){
var popo = document.getElementsByTagName(object);
for(var i = 0; i< popo.length; i ++){
popo [i] .playVideo();
}
}

通常这个函数工作正常,当我从

 < button onclick =playVideo();> play< / button> 

 < a href =javascript:playVideo();> play< / a> 

但如果我将它粘贴到浏览器控制台中,我按Return,

它不工作,并且有此错误:

未定义

http://oi57.tinypic.com/z1hjc.jpg


我做错了什么?


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:

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?

解决方案

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.

这篇关于chrome - 从浏览器控制台运行javascript函数“undefined”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆