更改表中的行顺序 - 防止更改标题

时间:2016-11-14 18:44:14

标签: javascript html

下面的代码允许重新排序表格行(向上或向下移动一行)

由于某种原因,IE11中的以下代码也允许更改标题行,虽然我指定“tbody tr:first”作为我的过滤器 我做错了什么?

		function upAction(){
			var row = $("input[name='select_radio']:checked").parents("tbody tr:first");				
			row.insertBefore(row.prev());
		}
		
		function downAction(){
			var row = $("input[name='select_radio']:checked").parents("tbody tr:first");
			row.insertAfter(row.next());
		}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

 <button onclick="upAction()">Up</button>
 <button onclick="downAction()">down</button>
<table  >
				<tr>
				   <th>Printer</th>
				   <th>Printer ID</th>
				   <th>Printer Description</th>
				</tr>
				<tbody>
              <tr>
                <td><input type="radio" name="select_radio"/></td>
                <td>x300</td>
                <td>3</td>
                <td>new printer installed in 3th floor</td>
              </tr>
              <tr>
                <td><input type="radio" name="select_radio"/></td>
                <td>x400</td>
                <td>5</td>
                <td>laser printer</td>
              </tr>
              <tr>
                <td><input type="radio" name="select_radio"/></td>
                <td>Office jet 3</td>
                <td>6</td>
                <td>old student printer</td>
              </tr>
  
              </tbody>
			</table>

0 个答案:

没有答案