开发者

How to get a value of a selected row from html?

开发者 https://www.devze.com 2023-03-18 04:23 出处:网络
I want to get a selected row val开发者_开发百科ue of a table when we click on a row, how can i do this?<script type=\"text/javascript\">

I want to get a selected row val开发者_开发百科ue of a table when we click on a row, how can i do this?


<script type="text/javascript">
window.onload=function() {
  var table = document.getElementById("table1");
  var tablerows = table.rows;
  for (var i=0, n=tablerows.length;i<n;i++) {
    tablerows[i].onclick=function() {
      alert(tablerows[i].textContent?tablerows[i].textContent:tablerows[i].innerText)
    }
  }
}
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号