dth981485742 2010-03-05 10:00
浏览 154

php dom获取节点的所有属性

is there any easy way of getting all attributes of a node without checking if it has that attribute? short, here's an example of what i'm trying to do: i have this short domdocument:

<p align=center style="font-size: 12px;">some text</p>
<a href="#" target="_blank">some link<a/>

okay.. now if i check p tag with getAttribute('align') i'll get the center value.. that's cool, but i want to see if p tag has also another attribute like style without checking for every attribute possible. on img tag i'll have to check for src, width, height, style, onclick, etc.. to verify if they exists.. but i'm thinking it might be a easier way of seeing all attributes.

  • 写回答

2条回答 默认 最新

  • dsi36131 2010-03-05 10:17
    关注

    Use this code, it will give you the specified attributes.

     
    
    <html>
    <script>
    function test()
    {
    getvalue=document.getElementById("iid").getAttribute("align")
    alert ( getvalue) ;
    }
    </script>
    
    <body>
    <p id=iid align="center" background="red" onclick="test();" >
    This is for testing
    php dom get all attributes of a node
    </p>
    </body>
    </html>
    

    Now when you click the conent of the p tag . It will show you align attirbute values.

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题