作者yorjing (托儿所婴儿)
看板PHP
标题[请益] php dom getElementById
时间Sun Dec 23 09:09:15 2007
<?
$dom = new DOMDocument('1.0', 'utf-8');
$r = $dom->createElement('palette');
$dom->appendChild($r);
$b = $dom->createElement( 'color','green');
$r->appendChild( $b );
$id=$dom->createAttribute('id');
$b->appendChild($id);
$idNum=$dom->createTextNode('1');
$id->appendChild($idNum);
$b= $dom->createElement( 'color','black');
$r->appendChild( $b );
$id=$dom->createAttribute('id');
$b->appendChild($id);
$idNum=$dom->createTextNode('2');
$id->appendChild($idNum);
$b= $dom->createElement( 'color','blue');
$r->appendChild( $b );
$id=$dom->createAttribute('id');
$b->appendChild($id);
$idNum=$dom->createTextNode('3');
$id->appendChild($idNum);
echo $dom->saveXML($dom->getElementById('1'));
?>
我想藉由getElementById取得<color>里面的元素
例如如code中的
echo $dom->saveXML($dom->getElementById('1'));
我想取得id=1的color
应该要出现"green"
没想到跑的结果却是
"greenblackblue "
1.请问各位大大
要怎样才能让他就由id取得green
2.我想让id值为数字
有相关的function吗?
先在这边谢谢大大帮我解决问题
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.224.207.6
※ 编辑: yorjing 来自: 61.224.207.6 (12/23 09:12)
※ 编辑: yorjing 来自: 61.224.207.6 (12/23 09:12)