1

I'm trying to retrieve the onclick value on a td element. This is what I have so far.

$xpath = new DOMXPath($dom);
$trs = $xpath->query("/html/body//table/tr");


foreach ($trs as $tr){
    $tds = $xpath->query("td", $tr);
    foreach ($tds as $td) {
        $a = $xpath->query("@onclick", $td);
        echo $a->nodeValue;
        echo $td->nodeValue;
    }
}

This doesn't seem to be working though.

Here's the structure

<table>
   <tr>
       <td>Name</td>
       <td onclick="blahblah">Author</td>
       <td>Title</td>
   </tr>
</table>
4

1 回答 1

0

$a 是一个 NodeList,你必须选择一个项目:

 @print($a->item(0)->nodeValue);
于 2012-09-01T21:43:49.517 回答