10/10/2018, 11:17
Giúp em bài Javacript này
<body>
<script language="javascript">
function taobang()
{
var SoHang=document.forms[0].elements[0].value*1
var SoCot=document.forms[0].elements[1].value*1
document.write("<h3>T?o b?ng "+SoHang+" hàng, "+SoCot+" c?t:<h3>");
document.write("<table border=1 bgcolor=yellow>");
for (var i=1;i<=SoHang;i++)
{
document.write("<tr>");
for (var j=1;j<=SoCot;j++)
{
/ document.write("<td align=center height="40" width="20">");
document.write(Math.floor(0+Math.random()*10));
document.write("</td>");
}
document.write("</tr>");
}
document.write("</table>");
}
</script>
<!-- Tạo Form-->
<form name="tao_bang">
Nhập số cột: <input type="text" name="cot" value="5" /><br />
Nhập số hàng: <input type="text" name="hang" value="5" /><br />
<input type="button" value="Click vao day" onclick="taobang()"/><br />
<input type="reset" value="Xóa" />
</form>
<!-- ------------------------------------- >
</body>
<script language="javascript">
function taobang()
{
var SoHang=document.forms[0].elements[0].value*1
var SoCot=document.forms[0].elements[1].value*1
document.write("<h3>T?o b?ng "+SoHang+" hàng, "+SoCot+" c?t:<h3>");
document.write("<table border=1 bgcolor=yellow>");
for (var i=1;i<=SoHang;i++)
{
document.write("<tr>");
for (var j=1;j<=SoCot;j++)
{
/ document.write("<td align=center height="40" width="20">");
document.write(Math.floor(0+Math.random()*10));
document.write("</td>");
}
document.write("</tr>");
}
document.write("</table>");
}
</script>
<!-- Tạo Form-->
<form name="tao_bang">
Nhập số cột: <input type="text" name="cot" value="5" /><br />
Nhập số hàng: <input type="text" name="hang" value="5" /><br />
<input type="button" value="Click vao day" onclick="taobang()"/><br />
<input type="reset" value="Xóa" />
</form>
<!-- ------------------------------------- >
</body>
Bài liên quan
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="title" content="" />
<style type="text/css">
#parse1 table{border-collapse:collapse;}#parse1 table td{padding:3px 7px;}
body{width:280px;margin:0 auto;}#parse1{clear:both;padding-top:23px;}input{float:right;}p{clear:both;}
</style>
</head>
<body>
<!-- Tạo Form-->
<form name="tao_bang" method="post" action="">
<p>Title o day</p>
<p> Nhập số cột:
<input type="text" name="cot" value="5" /></p>
<p>Nhập số hàng:
<input type="text" name="hang" value="5" /></p>
<p><input type="reset" value="Xóa" /><input type="button" value="Tạo bảng" onclick="taobang()" />
</p>
</form>
<!-- ------------------------------------- -->
<script language="javascript" type="text/javascript">
function taobang() {
var SoHang = document.forms[0].elements[0].value * 1;
var SoCot = document.forms[0].elements[1].value * 1;
var a11 = document.getElementById("parse1");
var chuoi1 = "";
chuoi1 +="<h3>Tạo bảng " + SoHang + " hàng, " + SoCot + " cột:<h3>";
chuoi1 +="<table border=1 bgcolor='#f0f0f0'>";
for (var i = 1; i <= SoHang; i++) {
chuoi1 +="<tr>";
for (var j = 1; j <= SoCot; j++) {
chuoi1 +="<td align=center height=\"40\" width=\"20\">";
chuoi1 += Math.floor(0 + Math.random() * 10);
chuoi1 +="</td>";
}
chuoi1 +="</tr>";
}
chuoi1 += "</table>";
a11.innerHTML = chuoi1;
return false;
};
</script>
<div id="parse1"></div>
</body>
</html>