0

一个简单的 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>
4

1 回答 1

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>

它应该有效。

于 2013-07-25T08:34:56.877 回答