[JavaScript ¼Ò½º]
-html ºÎºÐ
<html>
<head>
<title>test01</title>
<script src="p01.js"> </script>
</head>
<body>
<center><u><h1>Today Mission!<br><br></h1></center></u>
<h1>Q: input number is odd? or even?</h1>
<table width="500" border="1" align="center">
<tr>
<td bgcolor="#86E57F">
<h2>INPUT :
<input type="text" size="10" id="s1" maxlength="10">
<input type="button" value="Select!" onClick="p01()">
</h2>
<h2>OUPUT :
<input type="text" size="30" id="p1" maxlength="30">
</h2>
</td>
</tr>
</table>
<br>
<h1>Q: input number is prime? or not prime?</h1>
<table width="500" border="1" align="center">
<tr>
<td bgcolor="#86E57F">
<h2>INPUT :
<input type="text" size="10" id="s2" maxlength="10">
<input type="button" value="Select!" onClick="p02()">
</h2>
<h2>OUPUT :
<input type="text" size="30" id="p2" maxlength="30">
</h2>
</td>
</tr>
</table>
<br>
<h1>Q: input number's divisor?</h1>
<table width="500" border="1" align="center">
<tr>
<td bgcolor="#86E57F">
<h2>INPUT :
<input type="text" size="10" id="s3" maxlength="10">
<input type="button" value="Select!" onClick="p03()">
</h2>
<h2>OUPUT :
<input type="text" size="30" id="p3" maxlength="30">
</h2>
</td>
</tr>
</table>
</body>
</html>
-JavaScript ºÎºÐ
function p01()
{
var a = document.getElementById("s1").value;
var b = document.getElementById("p1");
if( a % 2==1) b.value="odd"
else b.value="even";
}
function p02()
{
var a = document.getElementById("s2").value;
var b = document.getElementById("p2");
var ff=0;
for(i=2; i<=a-1; i++){
if(a%i==0) ff=1;
}
if(ff==0) b.value="prime";
else b.value="not prime";
}
function p03()
{
var a = document.getElementById("s3").value;
var b = document.getElementById("p3");
b.value = "1";
for(i=2; i<=a; i++){
if(a % i == 0)b.value = b.value + ", " +i;
}
}
|