td中通过button绑定click事件实现跳转,以及获取同一table中另一td的值

1、通过button绑定事件跳转到同一页面的其他div
例:
js页面

 <table id = "tableid">
 <tr>
 <td id = "rcode">"123456"</td>
 <td><button type="button" id="buttonid" onclick="javascript:toManager(this)"></button></td>
 </tr>
 </table>
 <div id ="manage">跳转到的位置</div>

javascript脚本

<script type="text/javascript">
function toManager(r){
            window.location.hash = "#manager";
            var clickRow = r.parentNode.parentNode.rowIndex;//获取button行所在table的index
            alert(clickRow);
            var rcode = $(r).parent().parent().find("#rcode").val();  //rcode为另一td的id
            alert(rcode);
}
</script>

js页面需要引入jquery的插件

猜你喜欢

转载自blog.csdn.net/Ling1604/article/details/74392019