2010-03-24 8 views
0

자바 스크립트에서 일부 html 입력을 추가하고 제거하고 싶습니다. 추가 기능을 수행했습니다. 제대로 작동합니다. 제거 할 수 없습니다. 내 코드는자바 스크립트에서 제거 필드 추가

      fields = 1; 
         function addInput() { 
            if (fields != 10) { 
            document.getElementById('text').innerHTML += "<tr><td width='15%' align='left' valign='top' class='subheading'><input type='text' name='date[]' id='date[]' /></td><td width='15%' align='left' valign='top' class='subheading'><input type='text' name='time[]' id='time[]' /></td><td width='20%' align='left' valign='top' class='subheading'><input type='text' name='module[]' id='module[]' /></td><td width='15%' align='left' valign='top' class='subheading'><input type='text' name='organisation[]' id='organisation[]' /></td><td width='20%' align='left' valign='top' class='subheading' nowrap='nowrap'><input type='text' name='category[]' id='category[]' /></td><td width='20%' align='left' valign='top' class='text' nowrap='nowrap'>Add | Remove </td></tr>"; 
            fields += 1; 
           } else { 
            document.getElementById('text').innerHTML += "<br />Only 10 upload fields allowed."; 
         document.form.add.disabled=true; 
         } 
       } 
         fields1=10 
        function removeInput() { 
            if (fields1 !=1) { 
             document.getElementById('text').innerHTML += ""; 
             fields -= 1; 
               } 
             } 

내 PHP 함수를 하나라도 나에게 솔루션을 제공 할 수 있습니다

     function addSession() 
              {?> 
           <table cellpadding="5" cellspacing="0" width="100%"> 
         <tr> 
         <td width="10%" align="left" valign="top" colspan="6" bgcolor="#993333" class="heading">Add Session </span></td> 

         </tr><tr class="bgrow"> 
         <td width="10%" align="left" valign="top" class="subheading">Datum </span></td> 
        <td width="20%" align="left" valign="top" class="subheading">Tijd</td> 
       <td width="35%" align="left" valign="top" class="subheading">Module</td> 
       <td width="15%" align="left" valign="top" class="subheading">Organisatie</td> 
<td width="20%" align="left" valign="top" class="subheading" nowrap="nowrap">Category</td> 
<td width="20%" align="left" valign="top" class="subheading" nowrap="nowrap">Action</td> 
          </tr> 
          <tr > 
      <td width="15%" align="left" valign="top" class="subheading"><input type="text" name="date_0" id="date_0" /></td> 
<td width="15%" align="left" valign="top" class="subheading"><input type="text" name="time_0" id="time_0" /></td> 
<td width="20%" align="left" valign="top" class="subheading"><input type="text" name="module_0" id="module_0" /></td> 
<td width="15%" align="left" valign="top" class="subheading"><input type="text" name="organisation_o" id="organisation_o" /></td> 
<td width="20%" align="left" valign="top" class="subheading" nowrap="nowrap"><input type="text" name="cat_0" id="cat_0" /></td> 
<td width="20%" align="left" valign="top" class="text" nowrap="nowrap"><span onclick="addInput()" class="link">Add</span> | <span onclick="removeInput()" class="link">Remove </span></td> 
      </tr> 
      <tbody id="text"> 
         </tbody> 





        <?php 
         } 

         ?> 

되어 다음입니까?

답변

0

시도 :

var fields1 = 10; 
function removeInput() 
{ 

    if (fields1 !=1) 
    { 
     var someInput = document.getElementById('text'); 
     someInput.parentNode.removeChild(someInput.childNodes[0]); 
     fields1 -= 1; 
    } 
} 
+0

감사합니다! 작동하는 경우 – rajanikant

+0

, 대답을 수락하십시오;) 녹색으로 바뀌는 수표를 클릭해야합니다. – lugte098

관련 문제