donglei1699 2011-02-08 11:34
浏览 259
已采纳

使用php获取DIV元素的ID

-- edit --

I've made the question far more detailed here: Drupal aggregators and tailored output

-- original question --

Is it possible to get the id of an html div element on any given page using php so I can do something like:

if($divid == 'id-of-div') { do this; }

--edit--

To clarify:

I have a page on a website. It could be any page. On that website I have a div element which I want to be able to target using php to populate depending on the id of that div element. For example:

if($divid == 'div1') { $output = 'div 1 output'; }
if($divid == 'div2') { $output = 'div 2 output'; }
return $output;

Hope that helps...

-- re-edit(!) --

I've commented below but think it would probably be more useful in here:

Hi, sorry I'm not being more clear. I'm not a php expert (as you can probably tell!). I am theming a Drupal site at the moment and have a function that generates output to a block. These are the same kinds of block but they are unique by virtue of their div id's. I want to be able to tailor the generated output to these depending on which div area it is. Does that make any more sense? Thanks for your help so far, by the way

  • 写回答

2条回答 默认 最新

  • douhuo3696 2011-02-08 11:42
    关注

    I think you are misunderstanding the way PHP works. PHP is usually used to generate the raw HTML code of a page, but you usually don't use it to traverse the DOM of the output like you can in jQuery. (In theory, you can do this using output buffering and a HTML parser class, but it makes no sense at all.)

    There shouldn't be the need to find elements by ID because in order to put something into a DIV, you can do the following:

    <div id="mydiv">
    
      <?php echo "This is inside mydiv"; ?>
    
     </div>
    

    The resulting HTML will be a DIV that contains whatever you told PHP to output. This is usually enough.

    Not sure whether this helps you. If it doesn't, maybe add some more detail about what you want to do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题