如何在用户输入的javascript中显示“列表项”

时间:2014-02-07 01:36:49

标签: javascript list html user-input items

所以我需要在我的div中显示列表项,根据用户的输入并验证它是一个正值......这就是我所拥有的:

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

<body>
     <h1>Javascript</h1>
     <div id="main">
     <script>
          var x =prompt("How many list items would you like?:")

          if(x<0 || isNaN(x)){
               document.getElementById("main").innerHTML="Invalid input";
          }

          do {
               document.getElementById("main").innerHTML="This number is:" + x + '<br>';
          x++; }

         while (x<=10) 
     </script>
     </div>
</body>
</html> 

0 个答案:

没有答案