How to get the value of special attributes / custo

2019-08-15 20:34发布

<li data-docid="thisisthevaluetoget" class="search-results-item">
</li>

How to get the value of "data-docid"?

2条回答
Anthone
2楼-- · 2019-08-15 21:06

You may do this using JavaScript + jQuery. You may get the value and pass it into another php file using $_GET method.

an example is here

查看更多
家丑人穷心不美
3楼-- · 2019-08-15 21:09

You can use DOMDocument to get at the attributes:

$html = '<li data-docid="thisisthevaluetoget" class="search-results-item"></li>';
$doc = new DOMDocument;
$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('li');
foreach ($nodes as $node) {
    if ($node->hasAttributes()) {
        foreach ($node->attributes as $a) {
            echo $a->nodeName.': '.$a->nodeValue.'<br/>';
        }
    }
}
查看更多
登录 后发表回答