如何按类选择特定元素标签内的任何元素。我需要从元素“form”内部的“input”元素中检索属性“name”值。例如。有 2 个表单元素,名为 _arrived 和 _class。我需要从表单中检索所有属性名称值_class
$source = '
<form method="post" action"arrived.php" class="_arrived">
<input type="hidden" name="type1" value="value1" autocomplete="off">
<input type="hidden" name="type2" value="value2" autocomplete="off">
<input type="hidden" name="type3" value="value3">
<input type="hidden" name="type4" value="value4">
</form>
<form method="post" action="destiny.php" class="_class">
<input type="hidden" name="type1" value="value1" autocomplete="off">
<input type="hidden" name="type2" value="value2" autocomplete="off">
<input type="hidden" name="type3" value="value3">
<input type="hidden" name="type4" value="value4">
<input type="hidden" name="type5" value="value5">
<input type="hidden" name="type6" value="value6">
<input type="hidden" name="type7" value="value8">
<input type="hidden" name="type8" value="value9">
</form>';
$dom = new DOMDocument();
$dom->loadHTML($source);
$xpath = new DOMXpath($dom);
$items = $xpath->query('//form[@class="_class"]');
$form = $items->item(0);
$element = $form->getElementsByTagName("input");
foreach($element as $elemen){
foreach($elemen as $value){
echo $value->getAttribute('name').'<br>';
}
}
陪伴而非守候
温温酱
倚天杖