从用户和印刷明星那里获取信息

从用户和印刷明星那里获取信息

本文介绍了从用户和印刷明星那里获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,


I am trying to create a program in HTML using JavaScript. In which i want to take input from user in number and want to print the stars "*" of that number.

Kindly help and reply me with the accurate code.

Thanks


My Code is:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<script>
function PrintStars() {

var x = 0;
var y = 10;

for(x=0;x<10;x++)

{

for(y=0;y<=x;y=y+1)

{

document.getElementById("TableArea").innerHTML="<br>" + document.getElementById("etext").value;

document.write = "*";

}

}

}

</script>

<body>
Enter a Number: <input id="etext" type="text" placeholder="Enter a number here"/>
<p id="TableArea"></p>
<input type="button" Value="Print" onclick="PrintStars();"/>
</body>
</html>

推荐答案

<script>
      function PrintStars() {

          var _count = document.getElementById("etext").value;
          var count = parseInt(_count);
          document.getElementById("TableArea").innerHTML = "<br>" + count;
          var star = '';
          for (var i = 0; i < count; i++) {

              star += '*';

          }

          document.getElementById("spandisplay").innerHTML = star;



      }

  </script>







HTML:




HTML:

<div>
       Enter a Number:
       <input id="etext" type="text" placeholder="Enter a number here" />
       <p id="TableArea"></p>
       <input type="button" value="Print" onclick="PrintStars();" />
       <span id="spandisplay"></span>

   </div>



这篇关于从用户和印刷明星那里获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 11:48