2016-07-24 16 views
-2

javascript(document.write出力)とhtmlの背景画像を適用したいです。
私は何をする必要がありますか?このことができますhtmlとjavascriptの背景画像

<html> 
    <head> 
     <meta charset="utf-8"> 
     <script type="text/javascript"> 
      function loadBackgroundImage(){ document.body.style.backgroundImage="url('picture.jpg')";} 
     </script> 
    </head> 
    <body onload="loadBackgroundImage();"> 
    </body> 
</html> 

希望、実際にあなたのコードは次のようにする必要があり、ペーストビンリンクやコードのための

<!DOCTYPE html> 
<html> 
<head> 
<title>Useless Show English</title> 
<meta charset="utf-8"> 
<link rel="stylesheet" type="text/css" href="style.css"> 
</head> 
<body> 
<script type="text/javascript"> 
    function nickname() { 
     var a = window.prompt("Please enter your nick name:"); 
     if(a == "" || a == null || /*alt 0160*/a == " " || a == " ") 
     document.write("Error!"); 
     else 
     document.write("Hello," + " " + a + "!"); 
     document.write("</br>"); 
     document.write("<a href=\"uselessshow_select.html\"><button style=\"font-family: Arial, Helvetica, sans-serif;background-color: black;border: none;color: white;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;\">Back to the maine page<\/button>"); 
     document.write("<a href=\"uselessshow.html\"><button style=\"font-family: Arial, Helvetica, sans-serif;background-color: black;border: none;color: white;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;\">Back to the previous page<\/button>"); 

}  
</script> 
<button class="button" onclick="nickname()">If you want to start the script, please click here</button> 
<a href="uselessshow_select.html"><button class="button">Back</button></a> 
</body> 
</html> 
+0

ようこそ。 [How to ask](http://stackoverflow.com/help/how-to-ask)を参照して、[Minimal、Complete、and Verifiable example](http://stackoverflow.com/help/mcve)を作成してください。 – tmthydvnprt

答えて

-1

ありがとう:

これは私のコードの例です!

+0

ここで関数にjsコマンドを入れる必要がありますか? –

+0

@Haim Lvov、私は上記の答えを編集しました。アップデートの例を確認 –

+0

私は何が間違っているのか分かりませんが、まだ動作しません これは私がやったことです それを確認してください:http://pastebin.com/XpTyWUhQ –