日期:2014-05-17 浏览次数:20443 次
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);
}
<div id='myDivId' class="myDivClass" onclick="getTagInfo(this)">点我</div>
<span id='mySpanId' class="mySpanClass" onclick="getTagInfo(this)">点我</span>
<?php
$html = '<div id="myid" class="myclass"></div>';
$dom = new DOMDocument();
@$dom->loadHTML($html);
$x = new DOMXPath($dom);
foreach($x->query("//*") as $node)
{
echo $node->getAttribute("id"); //myid
echo '<br />';
echo $node->getAttribute("class"); //myclass
echo '<br />';
echo $node->nodeName; // div
}
?>