嗨,我有一個php腳本,它可以繪製一個表格,並且符合特定的條件。當繪製表格時,它位於名爲「窗口」的div內,並將該表格稱爲「visi」然後,我想使用下面的代碼來獲取表格中每個單元格的ID。我可以得到類名沒有問題,但從ID中絕對沒有。任何人都可以給我一個我做錯什麼的想法嗎?我已經嘗試了一個不在div裏面的表上的類似代碼,它工作正常。任何幫助都會很棒,我希望代碼有意義。獲取div(JS和HTML)中表格中單元格的標識
如果有幫助,這是繪製表的代碼(但是這是使用越來越表的信息後,JS/AJAX調用)
<?php
$table = "" ;
include '../database_sql/dbconnect.php' ;
include '../functions/job_details.php';
include '../functions/check_date.php';
include '../functions/stock_list.php' ;
include '../functions/allocated_on_date.php' ;
$jobdate = $_GET['jobdate'] ;
$jobnumber = $_GET['jobnumber'] ;
$jobname = $_GET['jobname'] ;
$screens = screens_per_job($jobnumber,$size) ;
$table = "<h2 align= 'center' > $jobname (Job Number $jobnumber) : Screens required : $screens </h2>" ;
$table .= "<table id='visi' width='480px' align='center' cellspacing='1' cellpadding='1' border='1' ><tr>" ;
// get stock list from DB
stock_list() ;
$len = count($stock);
$evresult = mysql_query("SELECT * FROM event WHERE jobnumber = '$jobnumber' ") ;
$event_row = mysql_fetch_array($evresult);
for ($counter = 0; $counter < $len; $counter++) {
$item = $stock[$counter] ;
$items = $item . "s" ;
$booked_for_job = $event_row[$items] ;
$result = mysql_query("SELECT * FROM $item ") ;
allocated_on_date($jobdate) ; // function
if ($booked_for_job) {
$count = 1 ;
$table .= "<td >$item<br> [$booked_for_job to Allocate] </td> " ;
WHILE ($row = mysql_fetch_array($result)) { ;
$booked_job = $screens[$item][$count]["job"] ; // from the allocated_on_date($jobdate) function
$description = $row['trailer_id'];
$class = $items ;
$id_items = $items . $count ;
$count ++ ;
if ($booked_job == $jobnumber) { // allocated to current job
$table .= "<td class='truckbox' > <div class='$class' id='$id_items' onClick='allocate(\"$booked_for_job\",\"$id_items\")' > " ;
$table .= "$num </div> </td>" ;
} ELSEIF ($booked_job === 0) { // available to allocated
$class .= "g" ;
$table .= "<td class='truckbox' > <div class='$class' id='$id_items' onClick='allocate(\"$booked_for_job\",\"$id_items\")' > " ;
$table .= "$num </div> </td>" ;
} ELSE { // allocated to ANOTHER job
$class .= "a" ;
$table .= "<td class='truckbox' > <div class='$class' id='$items' > " ;
$table .= "</td> " ;
}
} // while
$table .= "</tr>" ;
} ; // if
}; //for
$table .= "</table> " ;
$table .= "<table width='200px' align='center' cellspacing='12' cellpadding='1' ><tr>" ; // draw table buttons close and allocate
$table .= "</tr><tr>" ;
$table .= "<td class='truckbox' <div class='yesbutton' id='yes' onClick='confirm_allocate()' ; return false ; > ";
$table .= "<td class='truckbox' <div class='nobutton' id='no' onClick='hide()' > ";
$table .= "</tr></table> ";
echo $table ; // finally draw table
include '../database_sql/dbclose.php' ;
?>
我認爲你需要在代碼高亮另一個刺。確保每行代碼縮進至少4個空格或1個選項卡... – DisgruntledGoat 2009-10-24 14:12:58
是否可以顯示生成的表格? (HTML) – 2009-10-24 14:19:09
羅伯特, 這裏是鏈接到表 http://www.abbeysoft.co.uk/adi/diary_booking/diary_view.php從那裏你需要點擊'列表日期範圍,並確保範圍包括2009-10-15,然後點擊橙色的Pontefract Racecourse,這將顯示錶格。 如果你檢查的元素,你可以清楚地看到有一個唯一的ID爲每個細胞 謝謝... – Mick 2009-10-24 14:57:32