欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于JavaScript代碼實(shí)現(xiàn)自動(dòng)生成表格

 更新時(shí)間:2016年06月15日 10:43:58   投稿:mrr  
本文給大家分享一段js代碼實(shí)現(xiàn)輸入表格行數(shù)、列數(shù)自動(dòng)生成表格源代碼,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧

廢話不多說,直接給大家貼js代碼了,具體代碼如下所示:

//js實(shí)現(xiàn)輸入表格行數(shù)、列數(shù)自動(dòng)生成表格源代碼
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>自動(dòng)創(chuàng)建表格</title>
<style type="text/css">
table{
width:300px;
height:100px;
border:#0C9 1px solid;
border-collapse:collapse;
}
</style>
<script type="text/javascript" language="javascript">
function autocreate(){
//創(chuàng)建table表格
var table=document.createElement("table");
table.setAttribute("border","1");
table.setAttribute("background","red");
//獲取行數(shù)值
var line=document.getElementById("line").value;
//獲取列數(shù)值
var list=document.getElementById("list").value;
for(var i=0;i<=line;i++){
//alert(line);
//創(chuàng)建tr
var tr=document.createElement("tr");
for(var j=0;j<=list;j++){
//alert(list);
//創(chuàng)建td
var td=document.createElement("td");
tr.appendChild(td);
}
table.appendChild(tr);
}
document.getElementById("d1").appendChild(table);
}
</script>
</head>
<body>
<input type="text" id="line">行數(shù)
<input type="text" id="list">列數(shù)
<input type="button" value="添加表格" onclick="autocreate()">
<div id="d1" style="height:400px; width:300px;"></div>
</body>
</html>

以上所述是小編給大家介紹的基于JavaScript代碼實(shí)現(xiàn)自動(dòng)生成表格的全部敘述,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論