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>
Đây là bài tạo một table in ra ngẫu nhiên các số từ 0 đến 9, em muốn cái Table này hiện ngay bên dưới cái form để khi em click thêm lần nữa nó sẽ tiếp tục tạo một Table khác ngay phía dưới, vấn đề là mỗi lần em click vào thì nó tại tao ra một trang khác chưa cái Table mình tạo . Mọi nguoi2 có thể giúp em sửa lại và giải thích tại sao không ạ, em cảm ơn
www.baodientu.vn viết 13:33 ngày 10/10/2018
code thì mình chào thua rùi, chỉ có cách động viên bác thôi
kedienpro viết 13:29 ngày 10/10/2018
Làm sao để cài phần code nó highline vậy
hoahongxanh_22 viết 13:23 ngày 10/10/2018
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>
kedienpro viết 13:18 ngày 10/10/2018
Hic thanks đại ca nhiều lắm, em hiểu rồi
Bài liên quan
0