时间:2021-07-01 10:21:17 帮助过:2人阅读
  提供一个jQuery的解决方式  
   
 点我试试  
 点我试试 
  刚刚没注意将其写入到源代码中,使得格式错乱,看如下:  
  
function getTagInfo(e){	var str='';	if(jQuery(e).attr('id')){		str += 'id:'+jQuery(e).attr('id');	}else if(jQuery(e).attr('class')){		str += 'class:'+jQuery(e).attr('class');			}else{		str += '既没设置id也没设置class属性';	}	str += '\ntagName:'+jQuery(e).get(0).tagName;	alert(str);}  点我点我  
$html = '';$dom = new DOMDocument();@$dom->loadHTML($html);$x = new DOMXPath($dom); foreach($x->query("//div") as $node)//如果要span的话,//div 换成 //span {    echo $node->getAttribute("id");	echo '
';	echo $node->getAttribute("class");}    我也没看清楚,原来span或者div是不一定的,那就换  //* 然后 nodeName 获取HTML标签名。  
    
  
loadHTML($html);$x = new DOMXPath($dom); foreach($x->query("//*") as $node) {    echo $node->getAttribute("id"); //myid	echo '
';	echo $node->getAttribute("class"); //myclass	echo '
';	echo $node->nodeName; // div} ?>    [/code]  
  
 用PHPQUERY 可以实现吗 
  
  
 [/code]  
  
 用PHPQUERY 可以实现吗  
 sorry!PHPQUERY我没接触过