javascript實現在form中動態添加元素

來源:互聯網
上載者:User

<SCRIPT language=javascript>
var startL=1 //隨傳進的數組而不同
var allCount=1
var modified=0
var currentLine=-1
var line=-1;
function lightOn(ln){
  if (ln==null)
    ln=parseInt(event.srcElement.ln,10)
    for (i=startL;i<PLList.rows.length;i++)
      if (tdt[i].ln==ln)
        line=i
      cln=currentLine
      oldLine=-1
      for (i=startL;i<PLList.rows.length;i++)
        if (tdt[i].ln==cln)
          oldLine=i
        if (line==oldLine)
          return
        if (line>0)
          {
          currentLine=ln
          }
          }
function delIt()
          {
          line=parseInt(event.srcElement.ln,10)
          if (line>0)
            for (i=startL;i<PLList.rows.length;i++)
              if (tdt[i].ln==line)
              {
               
                PLList.deleteRow(i)
                }
                }
function newHospitalVisit()
                {
                  newRow=PLList.insertRow(PLList.rows.length);
                  newRow.id="tdt";
                  newRow.ln=allCount;
                  newRow.className="table-content";
                  newRow.onclick=lightOn;

                  c1=newRow.insertCell(0);
                  c1.id="delItem";
                  c1.ln=allCount;
      c1.width="77%";
                  c1.align='center';
                  c1.innerHTML='name1 <input type="txt" name="name1"  size="60"> name2 <input type="txt" name="name2">';

                  c2=newRow.insertCell(1);
                  c2.ln=allCount;
                  c2.onclick=delIt;
                  c2.width="23%";
                  c2.align='center';
                  c2.innerHTML='<input type="button" name="Button" value=" 刪除 "  ln='+allCount+'>';

                  allCount++
                }
function mouseOver()
                  {
                    event.srcElement.className="delMouseOver"
                  }
function mouseOut()
                  {
                    event.srcElement.className="scheduleButtonVisible"
                  }
function checkbox(cb)
                  {
                    cb.checked=!cb.checked
                  }
</SCRIPT>
<form name=frm>
<table align=center class="table-border" cellspacing=0 cellpadding=0 width="100%" id='PLList'>
  <TBODY>
  <tr class="table-title" align=center id=tdt>
   <td colspan="2">
   <table align=center cellspacing=0 cellpadding=0 width="100%" class="table-title">
     <tr align=center>
       <td width="23%">
      <INPUT name="name1" type=hidden>
   <INPUT name="name2" type=hidden>
   <input type="button" name="Button2" value="新加" class="functionButton" onclick=newHospitalVisit()>
    </td>

     </tr>
   </table>
   </td>
  </tr>

  </TBODY>
</table>
   </form>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.