将样式设置为innerHTML元素

时间:2015-01-14 23:05:55

标签: javascript html css

我正在制作一个Skate Dice计划并且碰壁了。我希望我的JavaScript获取一个元素,然后设置innerHTML的样式。

<html>
<head>
 <title>GameSpace</title>
 <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
 <body>
<input id="roll" type="button" value="Roll" onclick="show1()"/>
<img id="img1" src="http://www.clker.com/cliparts/X/w/P/Y/q/H/dice-1-md.png"/>

<img id="img2" src="http://www.clker.com/cliparts/X/V/S/C/I/x/dice-2-md.png"/>

<img id="img3" src="http://www.clker.com/cliparts/n/O/d/R/Y/c/dice-3-md.png"/>

<img id="img4" src="http://www.clker.com/cliparts/D/j/Z/R/5/P/dice-4-md.png"/>
<div id="popup"><p id="intext"> The dice have rolled! </p></div>
<script>
function reload()
{
window.location.reload(),
setTimeout(10000);
}

var rolldie1 = Math.random(), answer1; 

if (rolldie1 <= 0.16)
  {
    answer1 = "Ollie";
  } else if (rolldie1 <= 0.32)
    {
      answer1 ="Nollie";
    }
 else if (rolldie1 <= 0.48)
    {
      answer1 ="Fakie";
    }
 else if (rolldie1 <= 0.64)
    {
      answer1 ="Nose";
    }
 else if (rolldie1 <= 0.32)
    {
      answer1 ="Tail";
    }
 else if (rolldie1 <= 0.99)
    {
      answer1 ="Premo";
    }
function show1()
{
  var elem = document.getElementById("popup");
    elem.style.display = "block";

    document.getElementById("popup").innerHTML = document.getElementById("intext");
}
</script>
</body>
</html>

我希望document.getElementById获取弹出窗口,而innerHTML是文本,但它太小了,所以我希望它为innerHTML获取一个段落元素。

有人可以帮忙吗?

0 个答案:

没有答案