Javascript 我的html不是';t渲染?

Javascript 我的html不是';t渲染?,javascript,html,Javascript,Html,我完全卡住了。我所有的html文档都经过验证,并且彼此正确引用,但是当我加载主html时,它不会呈现 我的目标是有一个两面的页面:左侧显示默认的图像和标题,右侧包含一个按钮,用于通过不同的html文档在左侧加载不同的随机图像(5个)和标题 我用“iframes”来表达不同的观点 另外,如何更改iFrame的宽度 <!DOCTYPE html> <html> <head> <title>Free Jokes!</tit

我完全卡住了。我所有的html文档都经过验证,并且彼此正确引用,但是当我加载主html时,它不会呈现

我的目标是有一个两面的页面:左侧显示默认的图像和标题,右侧包含一个按钮,用于通过不同的html文档在左侧加载不同的随机图像(5个)和标题

我用“iframes”来表达不同的观点

另外,如何更改iFrame的宽度

<!DOCTYPE html>

<html>
    <head>
        <title>Free Jokes!</title>
        <meta charset="utf-8">
        <meta name="author" content="Justin Partovi, CS80 1184, Summer 2013">
        <link href="final%20project.css" rel="stylesheet">
    </head> 

    <body>
        <h1 id="shadow">Welcome to Free Jokes!</h1>
        <iframe id="left" src="left.html"></iframe>
        <iframe id="right" src="right.html"></iframe>
    </body>
</html>

免费笑话!
欢迎收看免费笑话!
左侧:

(请让我知道是否有更好的方式来实现我的目标,而不是我现在的方式)


你的笑话!
var随机数
函数clickForJoke(){
randomnumber=math.floor(1+math.random()*15);
开关(随机数){
案例1:
window.open(“joke1.html”,target=“right”);
打破
案例2:
window.open(“joke2.html”,target=“right”);
打破
案例3:
打开(“joke3.html”,target=“right”);
打破
案例4:
window.open(“joke4.html”,target=“right”);
打破
案例5:
window.open(“joke5.html”,target=“right”);
打破
违约:
window.open(“joke.html”,target=“right”);
右侧:

(我是不是把按钮弄错了?)


最终项目
单击此处可享受开玩笑的乐趣!
默认图像和位置:


默认笑话

点击右边的按钮可以得到一个免费的笑话


我还没有制作其他五个html文档。

这里的问题是右iframe上的按钮试图调用左iframe上的javascript函数

每个iframe都在自己的进程空间中运行,无法直接访问

parent.iframes[“LeftIFrameName”]。functionName
是一种方法。。。
在您的情况下,这将是
parent.iframes[“left”]。单击按钮onclick函数的forjoke()
,这里的问题是右侧iframe上的按钮试图调用左侧iframe上的javascript函数

每个iframe都在自己的进程空间中运行,无法直接访问

parent.iframes[“LeftIFrameName”]。functionName
是一种方法。。。
在您的情况下,它将是父级.iframes[“left”]。单击forjoke()按钮onclick函数

您不能只控制另一个iframe和另一个iframe。您必须从父级调用它

<button type="button" id="jokeButton" name="jokeButton" onclick="parent.iframes['left'].clickForJoke();">Click for your joking pleasure!</button>
让我们创建一个显示此页面的容器,并在右侧添加一个按钮

<div id="pageLoadArea"></div>
<div id="buttonArea"> 
    <a href="#" id="loadPage">Load Page</a>
</div>
现在,让我们在页面加载和单击按钮时执行此函数

$(function() {
    loadPage();
    $("#loadPage").on('click', loadPage);
});

完成了。只需进行一些样式设置,就完成了。

您不能只控制一个不同的iframe和另一个iframe。您必须从父级调用它

<button type="button" id="jokeButton" name="jokeButton" onclick="parent.iframes['left'].clickForJoke();">Click for your joking pleasure!</button>
让我们创建一个显示此页面的容器,并在右侧添加一个按钮

<div id="pageLoadArea"></div>
<div id="buttonArea"> 
    <a href="#" id="loadPage">Load Page</a>
</div>
现在,让我们在页面加载和单击按钮时执行此函数

$(function() {
    loadPage();
    $("#loadPage").on('click', loadPage);
});

完成了。只需进行一些样式设置,就完成了。

要更改iFrame的大小,可以使用css:

<iframe id="left" src="left.html" style="width:50%"></iframe>
<iframe id="right" src="right.html" style="width: 50%"></iframe>

您可能需要以自己的方式浮动或排列它们,使它们并排排列

看起来右侧iframe的文档正在调用在左侧框架中定义的函数。当iframe中有页面时,页面实际上存在于不同的空间中,并且信息量也有限,您甚至可以向父框架反馈

实际上,您可能需要刮除iframe,然后使用div或类似的东西:


要更改iFrame的大小,可以使用css:

<iframe id="left" src="left.html" style="width:50%"></iframe>
<iframe id="right" src="right.html" style="width: 50%"></iframe>

您可能需要以自己的方式浮动或排列它们,使它们并排排列

看起来右侧iframe的文档正在调用在左侧框架中定义的函数。当iframe中有页面时,页面实际上存在于不同的空间中,并且信息量也有限,您甚至可以向父框架反馈

实际上,您可能需要刮除iframe,然后使用div或类似的东西:


正如我在评论中所说的

<!DOCTYPE html>

<html>
  <head>
        <title>Your Joke!</title>
        <meta charset="utf-8">
  </head>
<!DOCTYPE html>

<html>
    <head>
        <title>Final project</title>
        <meta charset="utf-8">
        <link href="final%20project.css" rel="stylesheet">
    </head>

    <body>
        <button type="button" id="jokeButton" name="jokeButton" onclick="clickForJoke()">Click for your joking pleasure!</button>
        <script>
          var randomnumber

          function clickForJoke() {
              randomnumber=Math.floor( 1 + Math.random() * 15);

              switch ( randomnumber ) {
                  case 1:
                      window.open( "joke1.html", target="left" );
                      break;
                  case 2:
                      window.open( "joke2.html", target="left" );
                      break;
                  case 3:
                      window.open( "joke3.html", target="left" );
                      break;
                  case 4:
                      window.open( "joke4.html", target="left" );
                      break;
                  case 5:
                      window.open( "joke5.html", target="left" );
                      break;

                  default:
                      window.open( "joke.html", target="left" );
              }
          }
      </script>
    </body>
</html>

你的笑话!

<!DOCTYPE html>

<html>
  <head>
        <title>Your Joke!</title>
        <meta charset="utf-8">
  </head>
<!DOCTYPE html>

<html>
    <head>
        <title>Final project</title>
        <meta charset="utf-8">
        <link href="final%20project.css" rel="stylesheet">
    </head>

    <body>
        <button type="button" id="jokeButton" name="jokeButton" onclick="clickForJoke()">Click for your joking pleasure!</button>
        <script>
          var randomnumber

          function clickForJoke() {
              randomnumber=Math.floor( 1 + Math.random() * 15);

              switch ( randomnumber ) {
                  case 1:
                      window.open( "joke1.html", target="left" );
                      break;
                  case 2:
                      window.open( "joke2.html", target="left" );
                      break;
                  case 3:
                      window.open( "joke3.html", target="left" );
                      break;
                  case 4:
                      window.open( "joke4.html", target="left" );
                      break;
                  case 5:
                      window.open( "joke5.html", target="left" );
                      break;

                  default:
                      window.open( "joke.html", target="left" );
              }
          }
      </script>
    </body>
</html>

最终项目
单击此处可享受开玩笑的乐趣!
var随机数
函数clickForJoke(){
randomnumber=Math.floor(1+Math.random()*15);
开关(随机数){
案例1:
window.open(“joke1.html”,target=“left”);
打破
案例2:
window.open(“joke2.html”,target=“left”);
打破
案例3:
打开(“joke3.html”,target=“left”);
打破
案例4:
打开(“joke4.html”,target=“left”);
打破
案例5:
打开(“joke5.html”,target=“left”);
打破
违约:
window.open(“joke.html”,target=“left”);
}
}

演示:

如我在评论中所说

<!DOCTYPE html>

<html>
  <head>
        <title>Your Joke!</title>
        <meta charset="utf-8">
  </head>
<!DOCTYPE html>

<html>
    <head>
        <title>Final project</title>
        <meta charset="utf-8">
        <link href="final%20project.css" rel="stylesheet">
    </head>

    <body>
        <button type="button" id="jokeButton" name="jokeButton" onclick="clickForJoke()">Click for your joking pleasure!</button>
        <script>
          var randomnumber

          function clickForJoke() {
              randomnumber=Math.floor( 1 + Math.random() * 15);

              switch ( randomnumber ) {
                  case 1:
                      window.open( "joke1.html", target="left" );
                      break;
                  case 2:
                      window.open( "joke2.html", target="left" );
                      break;
                  case 3:
                      window.open( "joke3.html", target="left" );
                      break;
                  case 4:
                      window.open( "joke4.html", target="left" );
                      break;
                  case 5:
                      window.open( "joke5.html", target="left" );
                      break;

                  default:
                      window.open( "joke.html", target="left" );
              }
          }
      </script>
    </body>
</html>

你的笑话!

<!DOCTYPE html>

<html>
  <head>
        <title>Your Joke!</title>
        <meta charset="utf-8">
  </head>
<!DOCTYPE html>

<html>
    <head>
        <title>Final project</title>
        <meta charset="utf-8">
        <link href="final%20project.css" rel="stylesheet">
    </head>

    <body>
        <button type="button" id="jokeButton" name="jokeButton" onclick="clickForJoke()">Click for your joking pleasure!</button>
        <script>
          var randomnumber

          function clickForJoke() {
              randomnumber=Math.floor( 1 + Math.random() * 15);

              switch ( randomnumber ) {
                  case 1:
                      window.open( "joke1.html", target="left" );
                      break;
                  case 2:
                      window.open( "joke2.html", target="left" );
                      break;
                  case 3:
                      window.open( "joke3.html", target="left" );
                      break;
                  case 4:
                      window.open( "joke4.html", target="left" );
                      break;
                  case 5:
                      window.open( "joke5.html", target="left" );
                      break;

                  default:
                      window.open( "joke.html", target="left" );
              }
          }
      </script>
    </body>
</html>

最终项目
点击查找