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

JS如何生成動態(tài)列表

 更新時間:2020年09月22日 10:25:40   作者:Mr順  
這篇文章主要為大家詳細(xì)介紹了JS如何生成動態(tài)列表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了JS如何生成動態(tài)列表的具體代碼,供大家參考,具體內(nèi)容如下

思路: JS中寫函數(shù)----HTML中利用表單元素獲取用戶輸入的行和列的值,調(diào)用JS中的函數(shù)。
主要用到的知識有:JS就不說了,表單元素,以及其屬性value,和表格…

代碼:

<!doctype html>
<html>
<head>
 <meta charset = "utf-8">
 <title>創(chuàng)建動態(tài)表格</title>
 <style>
  #form1{
   padding:10px; width:400px; margin:0 auto;
  }
 </style>
 <script type = "text/javascript">
  function createTable() { 
   var r1 = document.getElementById( "row" ).value;
   var c1 = document.getElementById( "col" ).value; 
   var n = 1;  //單元格中的文字
   var str = "<table width = '100%' border = '1' cellspacing = '0' cellpadding = '0' ><tbody>";
   for(i = 0; i<r1; i++) {
    str = str+"<tr align = 'center'>"
    for(j = 0; j<c1; j++) str = str+"<td>"+(n++)+"</td>"
    str = str+"</tr>"
   }
   var d1 = document.getElementById( "d1" );
   d1.innerHTML = str+"</tbody></table>";
  }
 </script>
</head>
<body>
 <form id = "form1" name = "form1" method = "post" action = "">
  <fieldset>
  <legend>動態(tài)創(chuàng)建表格</legend>
  輸入表格的行數(shù):<input type = "text" id = "row" placeholder = "請輸入表格的行數(shù)" required autofocus /><br/>
  輸入表格的列數(shù):<input type = "text" id = "col" placeholder = "請輸入表格的列數(shù)" /><br/>
  <input type = "button" id = "ok" value = "產(chǎn)生表格" onclick = "createTable()"/>
  </fieldset>
 </form>
 <div id = "d1"></div>
</body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論