2017-04-18 4 views
0

プロンプト()変数は、htmlファイルの<script>タグ内にある場合にのみ機能しますが、それはできません。代わりに私は.jsファイルでそれを持っていますが、私はページを更新するときに私にプロンプ​​トを表示しません。ファイルはロードされていますが、何も起こりません。これがどうして起こるのか?Javascriptプロンプトはインラインでのみ動作し、外部ファイルではありません

は、あなたが探している属性がsrcないhrefあるコード

var userChoice = prompt("Do you choose rock, paper or scissors?"); 
var computerChoice = Math.random(); 

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title></title> 

    <link rel="stylesheet" type="text/css" href="index.css"> 

    <script type="text/javascript" href="index.js"></script> 
</head> 
<body> 
    <div class="display"> 

    </div> 
</body> 
</html> 
+0

あなたのコードを質問に追加できますか? ([mcve]を参照)。 – evolutionxbox

+0