Jquery 상하 이동 식 표 만 들 기

5006 단어 jquery
current.insertBefore(prev); current.insertAfter(next);
 
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>  </title> 
  <style type="text/css">
.editText
{
    border-width:1px;
    border-top-style:none;
    border-left-style:none;
    border-right-style:none;
    border-bottom-style:solid;
    border-color:#030;
    width:100%;
}
</style> 
  <script src="jquery.js" type="text/javascript">
</script> 
  <script type="text/javascript">
function moveUp(obj)
{
    var current=$(obj).parent().parent();
    var prev=current.prev();
    if(current.index()>1)
    {
        current.insertBefore(prev);
    }
}
function moveDown(obj)
{
    var current=$(obj).parent().parent();
    var next=current.next();
    if(next)
    {
        current.insertAfter(next);
    }
}
</script> 
 </head> 
 <body> 
  <table class="grid" width="100%" border="1" cellspacing="0" cellpadding="0"> 
   <tbody>
    <tr> 
     <td>     </td> 
     <td>     </td> 
     <td>      </td> 
     <td>  </td> 
     <td>    </td> 
     <td>        </td> 
     <td>    </td> 
    </tr> 
    <tr> 
     <td>1</td> 
     <td><input type="text" name="textfield" class="editText" id="textfield" /></td> 
     <td> </td> 
     <td><input type="text" name="textfield5" id="textfield5" /></td> 
     <td><input type="checkbox" name="checkbox" id="checkbox" /></td> 
     <td><input type="checkbox" name="checkbox5" id="checkbox5" /></td> 
     <td><a href="javascript:void(0)" onclick="moveUp(this)">  </a><a href="javascript:void(0)" onclick="moveDown(this)">  </a></td> 
    </tr> 
    <tr> 
     <td>2</td> 
     <td><input type="text" name="textfield2" id="textfield2" /></td> 
     <td> </td> 
     <td><input type="text" name="textfield6" id="textfield6" /></td> 
     <td><input type="checkbox" name="checkbox2" id="checkbox2" /></td> 
     <td><input type="checkbox" name="checkbox6" id="checkbox6" /></td> 
     <td><a href="javascript:void(0)" onclick="moveUp(this)">  </a><a href="javascript:void(0)" onclick="moveDown(this)">  </a></td> 
    </tr> 
    <tr> 
     <td>3</td> 
     <td><input type="text" name="textfield3" id="textfield3" /></td> 
     <td> </td> 
     <td><input type="text" name="textfield7" id="textfield7" /></td> 
     <td><input type="checkbox" name="checkbox3" id="checkbox3" /></td> 
     <td><input type="checkbox" name="checkbox7" id="checkbox7" /></td> 
     <td><a href="javascript:void(0)" onclick="moveUp(this)">  </a><a href="javascript:void(0)" onclick="moveDown(this)">  </a></td> 
    </tr> 
    <tr> 
     <td>4</td> 
     <td><input type="text" name="textfield4" id="textfield4" /></td> 
     <td> </td> 
     <td><input type="text" name="textfield8" id="textfield8" /></td> 
     <td><input type="checkbox" name="checkbox4" id="checkbox4" /></td> 
     <td><input type="checkbox" name="checkbox8" id="checkbox8" /></td> 
     <td><a href="javascript:void(0)" onclick="moveUp(this)">  </a><a href="javascript:void(0)" onclick="moveDown(this)">  </a></td> 
    </tr> 
   </tbody>
  </table>  
 </body>
</html>

좋은 웹페이지 즐겨찾기