简体   繁体   English

如何在js中获取所选单元格的行和列的表数据

[英]How to get the row wise and column wise table data of a selected cell in js

[![This is a table designed using HTML][1]][1] [![这是使用HTML设计的表格] [1]] [1]

Hi, In this table any cell can be selected by the user(even multiple cells).What i need is that once the submit button is pressed the corresponding row wise and column wise table data ie B and 1pm as of this example must be stored in the database. 嗨,在这个表中用户可以选择任何单元格(甚至多个单元格)。我需要的是,一旦按下提交按钮,就必须存储相应的按行和按列的表数据,即本示例中的B和1pm在数据库中。

<script type="text/javascript">
function change()
{
var cells = document.querySelectorAll("td");

for (var i = 0; i < cells.length; i++) {
    cells[i].addEventListener("click", function() {
       this.className= this.className == "white" ? "green" : "white";
    });
}
}

function alert()
{
var cells = document.querySelectorAll("td");

for(var i=0;i<cells.length;i++)
{
if(cells[i].className.match("green"))
{
document.getElementById('p1').innerHTML="Appointment fixed";

}

}

}

</script>

This is the js for cell selection and alert message on submit if any one of the cells is selected 如果选择了任何一个单元格,这是用于单元格选择和提交警报消息的js

I'm new to js,so someone kindly help me out with this.Thankyou. 我是js的新手,所以有人可以帮助我。谢谢。

In the HTML of each td element you can save its column name and row name like this 在每个td元素的HTML中,您可以像这样保存其列名和行名

<td data-r="Fairlands_B" data-c="1pm" class="green"></td>

Then to get the row and column data out of the clicked td: 然后从单击的td中获取行和列数据:

var place=this.dataset.r;
var time=this.dataset.c;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM