Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 使用jquery选择后如何查找td的表头_Jquery Ui_Jquery_Jquery Selectors - Fatal编程技术网

Jquery ui 使用jquery选择后如何查找td的表头

Jquery ui 使用jquery选择后如何查找td的表头,jquery-ui,jquery,jquery-selectors,Jquery Ui,Jquery,Jquery Selectors,嗨 如上图所示,我正在创建一个简单的日历用于我的项目 表格的Html格式: <table> <tr><th>time</th><th>2012-12-23</th>etc..</tr> <tr><th>09:00AM</th><td></td><td></td>etc...</tr> 非常感谢很容易获得时间-因为它是

嗨 如上图所示,我正在创建一个简单的日历用于我的项目

表格的Html格式:

<table>
<tr><th>time</th><th>2012-12-23</th>etc..</tr>
<tr><th>09:00AM</th><td></td><td></td>etc...</tr>

非常感谢

很容易获得时间-因为它是单击行的第一个单元格。要获取“日期”列,我们可以使用
index
方法

$('td').click(function() {
  var $cell = $(this);
    time = $cell.parent().children(':first').text();
    date = $cell.closest('table').children(':first').find('th').eq($cell.index()).text();
    alert(date + ' ' + time);
});​

var time = td.parentNode.cells[0].firstChild.nodeValue,
    date = td.parentNode.parentNode.rows[0].cells[td.cellIndex].firstChild.nodeValue;
试试这个:

$('td').click(function() {
    var $td = $(this);
    var $th = $td.closest('table').find('th').eq($td.index());

    // Get the header text...
    alert($th.text());

    var $firstTD = $td.closest('tr').find('td:first');

    // Get the first td text...
    alert($firstTD.text());
});​

这完全取决于您没有共享的现有代码。还有,到目前为止你试过什么?在发布任何问题之前,请遵循您需要确认的步骤。请记住,只有你想要的东西,你问自己它是如何编程的,这本身不符合编程问题的资格。-根据标签,您似乎已经知道答案:-请参考手册了解您的支持选项。添加了更多详细信息,我之前没有让问题看起来太大!,是的,我知道这是一个选择器问题,但我一直在尝试,尝试着找不出最接近的('table')!!,谢谢任何方式这个答案已经被关闭,所以我在给出答案,因为
jQuery.selective
有它自己的方法来做这种工作,这是正确的方式,IMO.@Sheikh这就是我要找的,谢谢aloti不知道你在说什么,朋友,对不起,我不是js人:(
jQuery.selective
有自己的方法来做这类工作,在我看来,
jQuery.selective
有自己的方法来做这类工作,在我看来,@raina77ow,你救了我的救命恩人。上帝保佑你
jQuery.selective
有自己的方法来做这类工作,在我看来。
$('td').click(function() {
  var $cell = $(this);
    time = $cell.parent().children(':first').text();
    date = $cell.closest('table').children(':first').find('th').eq($cell.index()).text();
    alert(date + ' ' + time);
});​
var time = td.parentNode.cells[0].firstChild.nodeValue,
    date = td.parentNode.parentNode.rows[0].cells[td.cellIndex].firstChild.nodeValue;
$('td').click(function() {
    var $td = $(this);
    var $th = $td.closest('table').find('th').eq($td.index());

    // Get the header text...
    alert($th.text());

    var $firstTD = $td.closest('tr').find('td:first');

    // Get the first td text...
    alert($firstTD.text());
});​