1
回答
为什么html可以-1,但是无法实现+1
开发十年,就只剩下这套Java开发体系了   

上代码

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>演示:jQuery实现表格行上移下移和置顶</title>
<meta name="keywords" content="jquery,滑动" />
<meta name="description" content="Helloweba文章结合实例演示HTML5、CSS3、jquery、PHP等WEB技术应用。" />
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<style type="text/css">
.demo{width:600px; margin:60px auto 10px auto; font-size:16px}
.table {border-collapse: collapse !important;width: 100%;max-width: 100%;margin-bottom: 20px;}
.table td,.table th {background-color: #fff !important;}
.table-bordered th,.table-bordered td {border: 1px solid #ddd !important;}
.table tr td {padding: 8px;line-height: 1.42857143;vertical-align: middle;border-bottom: 1px solid #ddd;}
.table tr:hover {background-color: #f5f5f5;}
</style>
<script type="text/javascript" src="http://libs.useso.com/js/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function(){
	//上移
	var up = $(".up")
    up.click(function() {
        var tr = $(this).parents("tr");
        var atr = $(this).parents("tr").prev();
        if (tr.index() != 0) {
			//tr.fadeOut().fadeIn();
			tr.prev().before(tr);
            tr.children()[0].innerHTML= tr.children()[0].innerText-1;
            atr.children()[0].innerHTML= atr.children()[0].innerText+4;
        }
    });
    //下移
    var down = $(".down");
    var len = down.length;
    down.click(function() {
        var tr = $(this).parents("tr");
        if (tr.index() != len - 1) {
			//$tr.fadeOut().fadeIn();
            tr.next().after(tr);
        }
    });
});
</script>
</head>

<body>

<div id="main">
	<div class="demo">
		<table class="table">
			<tr>
				<td>1</td>
				<td>2015-04-25</td>
				<td><a href="#" class="up">上移</a> <a href="#" class="down">下移</a> <a href="#" class="top">置顶</a></td>
			</tr>
			<tr>
				<td>2</td>
				<td>2015-04-18</td>
				<td><a href="#" class="up">上移</a> <a href="#" class="down">下移</a> <a href="#" class="top">置顶</a></td>
			</tr>
			<tr>
				<td>3</td>
				<td>2015-04-10</td>
				<td><a href="#" class="up">上移</a> <a href="#" class="down">下移</a> <a href="#" class="top">置顶</a></td>
			</tr>
			<tr>
				<td>4</td>
				<td>2015-03-29</td>
				<td><a href="#" class="up">上移</a> <a href="#" class="down">下移</a> <a href="#" class="top">置顶</a></td>
			</tr>
		</table>
	</div>
	
	
</div>
</body>
</html>


为什么这里执行“-1”的时候,编号会按照整形数据去计算,但是“+1”的时候就按照字符串格式去加了呢??



<无标签>
举报
弧线之内
发帖于3年前 1回/152阅
顶部