0

我的 html 没有显示我写的任何内容。我要实现的目标是在右侧“div”上制作一个按钮,以便从左侧 div 上的 5 个生成中随机开玩笑。问题是我不知道如何制作一个让按钮产生笑话的功能。这个笑话将在一个单独的 html 中,当您加载 html 时,我将使用它来替换左侧 div 中的默认值。很抱歉,如果这真的语无伦次,但感谢您的承诺。

这是我到目前为止所拥有的:

主要的html:

<html>
<head>
    <title>Free Jokes!</title>
    <meta charset="utf-8">
    <link href="final project.css" rel="stylesheet">
</head> 

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

左侧 div html:

<!DOCTYPE html>

<html>
    <head>
        <title>Free Jokes!</title>
        <script>
        var randomnumber

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

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

        default:
            window.open( "joke.html", target="right" );

和外部CSS:

body
{
    background-color: lightblue;
}

#shadow
{
    text-shadow: -5px -8px 2px lightgreen;
    font-size: 600%;
}

left
{
    float:left;width:30%;
}

right
{
    float:right;width:70%;
}

先感谢您!

4

2 回答 2

0

Well, first of all, your CSS selectors are wrong. They should be:

body
{
    background-color: lightblue;
}

#shadow
{
    text-shadow: -5px -8px 2px lightgreen;
    font-size: 600%;
}

#left
{
    float:left;width:30%;
}

#right
{
    float:right;width:70%;
}

Secondly, you can't use the src attribute on a div tag. That makes no sense!

If you're trying to include content into the page from somewhere else, you need to use an iframe tag. Regardless of my feelings towards using this, it should be more like:

<html>
<head>
    <title>Free Jokes!</title>
    <meta charset="utf-8">
    <link href="final project.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>

http://www.w3schools.com/tags/tag_iframe.asp

Good luck!

于 2013-07-25T09:55:34.030 回答
0

You can't do that

<div id="left" src="left.html"/> //src not allowed inside div tag

Use Iframe instead.

Iframe are used for that purpose i.e. to include another html page in the body.And you can very well enclose Iframe inside div

visit this for a good tutorial on Iframes.

于 2013-07-25T09:55:50.313 回答