添加iFrame后无法找到功能

时间:2013-07-25 08:11:29

标签: javascript

一个简单的Hello world函数和一个说明错误的按钮。评论iFrame - 就像一个魅力。删除评论 - 致命错误。我很困惑。

来源:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
  </head>
    <body>
  <button onclick="helloWorld()">Click me</button>

 <iframe id="ytplayer" type="text/html" width="640" height="390"
  src="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"/> 
</body>
</html>
<script>
    function helloWorld() {
        console.log("Hello world");
    }
</script>

1 个答案:

答案 0 :(得分:0)

正确放置 javascript

<head>
   <meta charset="utf-8" />
   <script>
      function helloWorld() {
         console.log("Hello world");
      }
   </script>
</head>

<iframe>重新输入正确的语法。

<iframe id="ytplayer" type="text/html" width="640" height="390"
        src="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com">
</iframe>

完整代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <script>
        function helloWorld() {
            alert("Hello world");
        }
    </script>
</head>
<body>
    <button onclick="helloWorld()">Click me</button>

    <iframe id="ytplayer" type="text/html" width="640" height="390"
            src="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com">
    </iframe>
</body>
</html>

它应该有用。