问题寻找之表格内标签定位行数

来源:互联网 发布:网络实体店怎么开 编辑:程序博客网 时间:2024/06/07 17:46
var index = $(this).parent().parent().prevAll().length + 1;核心
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><script src="js/jquery-1.8.2.js"></script></head><body><table border="\" cellspacing="" cellpadding=""><tr><th>Header1</th><th>Header2</th><th>Header3</th><th>Header4</th></tr><tr><td><input type="text"  class="in1" value="11111" /></td><td><input type="text"  class="in2" value="22222" /></td><td><select name="" class="sel"><option value="1">tttt</option><option value="2">rrrr</option><option value="3">yyyy</option></select></td><td><input type="text" class="in3"  value="44444" /></td></tr><tr><td><input type="text" class="in1"  value="111111" /></td><td><input type="text" class="in2" value="222222" /></td><td><select name="" class="sel"><option value="1">tttt</option><option value="2">rrrr</option><option value="3">yyyy</option></select></td><td><input type="text" class="in3"  value="444444" /></td></tr><tr><td><input type="text"  class="in1" value="1111111" /></td><td><input type="text"  class="in2" value="2222222" /></td><td><select name="" class="sel"><option value="1">tttt</option><option value="2">rrrr</option><option value="3">yyyy</option></select></td><td><input type="text" class="in3"  value="4444444" /></td></tr></table></body><script>$(function(){var i = 0;/*$(".in1").eq(i).on('click',function(){alert($(".in").index(this));$(this).parent().parent().children().eq("2").children().html('<option value="2">wwwww</option>');})*/$(".in1").on('click',function(){//alert($(".in").index(this));//找到tr后,在prevAll()var index = $(this).parent().parent().prevAll().length + 1;alert(index);//$(this).parent().parent().children().eq("2").children().html('<option value="2">wwwww</option>');})})</script></html>


 
原创粉丝点击