표 케이스

4075 단어
이름과 나이 추가
window.onload= function () {
        var btn=document.getElementById('btn');
        var username=document.getElementById('username');
        var age=document.getElementById('age');
        var otab=document.getElementById('otab');
        btn.onclick= function () {
            var otr=document.createElement('tr');

            var otd1=document.createElement('td');
            otd1.innerHTML=otab.tBodies[0].rows.length+1;
            otr.appendChild(otd1);

            var otd2=document.createElement('td');
            otd2.innerHTML=username.value;
            otr.appendChild(otd2);

            var otd3=document.createElement('td');
            otd3.innerHTML=age.value;
            otr.appendChild(otd3);

            otab.tBodies[0].appendChild(otr);
        };

    };

한 줄 삭제
    window.onload= function () {
        var btn=document.getElementById('btn');
        var username=document.getElementById('username');
        var age=document.getElementById('age');
        var otab=document.getElementById('otab');
        var oid=otab.tBodies[0].rows.length;
        btn.onclick= function () {
            var otr=document.createElement('tr');
            var otd1=document.createElement('td');
            otd1.innerHTML=++oid;
            otr.appendChild(otd1);

            var otd2=document.createElement('td');
            otd2.innerHTML=username.value;
            otr.appendChild(otd2);

            var otd3=document.createElement('td');
            otd3.innerHTML=age.value;
            otr.appendChild(otd3);

            var otd4=document.createElement('td');
            var oa=document.createElement('a');
            oa.innerHTML=' ';
            oa.href="javascript:;";
            otd4.appendChild(oa);
            otr.appendChild(otd4);
            oa.onclick= function () {
                otab.tBodies[0].removeChild(this.parentNode.parentNode);
            };

            otab.tBodies[0].appendChild(otr);
        };

    };

검색



    
    
    <script>
    window.onload= function () {
        var text1=document.getElementById('username');
        var btn=document.getElementById('btn');
        var otab=document.getElementById('otab');
        btn.onclick= function () {
            for(var i=0;i<otab.tBodies[0].rows.length;i++){
                var arr=text1.value.split('');
                otab.tBodies[0].rows[i].style.background='';

                for(var j=0;j<arr.length;j++){
                    if(otab.tBodies[0].rows[i].cells[1].innerHTML.search(arr[j])!=-1){
                        otab.tBodies[0].rows[i].style.background='yellow';
                    }
                }
            }
        };
    };
</script>


<form action="###">
     :<input type="text" id="username"/>
    <input type="button" value=" " id="btn"/>
</form>
<br/>
<br/>

<table border="1px" cellpadding="0" cellspacing="0" id="otab">
<thead>
  <th>id</th>
  <th> </th>
  <th> </th>
</thead>
<tbody>
  <tr>
      <td>1</td>
      <td> </td>
      <td>18</td>
  </tr>
  <tr>
      <td>2</td>
      <td> </td>
      <td>15</td>
  </tr>
  <tr>
      <td>3</td>
      <td> </td>
      <td>16</td>
  </tr>
  <tr>
      <td>4</td>
      <td> </td>
      <td>16</td>
  </tr>
</tbody>
</table>



</code></pre> 
</article>
                            </div>
                        </div>

좋은 웹페이지 즐겨찾기