jquery新手问题 jquery index()用法问题
关于jquery中index()函数的问题
<body>
<table>
<thead>
<tr>
<th colspan="2">鼠标点击表格项就可以编辑</th>
</tr>
</thead>
<tbody>
<tr>
<th>学号</th>
<th>姓名</th>
</tr>
<tr>
<td id="id">000001</td>
<td id="name">张三</td>
</tr>
<tr>
<td id="id">000002</td>
<td id="name">李四</td>
</tr>
<tr>
<td id="id">000003</td>
<td id="name">王五</td>
</tr>
<tr>
<td>000004</td>
<td>赵六</td>
</tr>
</tbody>
</table>
<input id="btnSave" type="button" value="确定">
</body>
页面很简单,就一个table
然后,点击提交的时候
$("#btnSave").click(function(){//按钮点击事件
var str = "";
var users = new Array();
$("table tbody tr").each(function(){
var tr = $(this);
var u = new User();
tr.find("td").each(function(){
var td = $(this);
var att = td.attr("id");
var value = td.html();
alert($(this).index());
if(att=="id") {
str = str + "{\"" + att +"\":\""+value +"\",";
u.id =value;
}
if(att=="name") {
str = str + "\""+att +"\":\""+value +"\" }";
u.name = value;
}
});
if(u.id!="") {
users.push(u);
}
});
str = "{\"users\":[" +str+"]}";
});
function User(id,name) {