dtiopy6088 2016-10-10 05:56
浏览 55

在PHP中更新标记的innerHTML属性

I am trying to update innerHTML property of paragraph tag in PHP. I made a rest API call that gets the date and after parsing it. I am adding the result(HTML table constructed by parsing the results from API) to a <P> tag already in page. I am using following PHP code to do so:

$dom = new DOMDocument();
$child = $dom->createElement('p',$myresult);
$dom->appendChild($child);
$dom->SaveHTML();

$myresult is the string that contain html table with information. The above lines are executed smoothly but no change in p tag content.

I tried this too, but no change in output:

<?php echo "<script>document.getElementByID("#id").innerHTML = ". $myresult."</script>"

Am I doing anything wrong?

  • 写回答

3条回答 默认 最新

  • dongxuxian1123 2016-10-10 06:00
    关注

    Try:

    <?php echo "<script>document.getElementById(\"id\").innerHTML=".$myresult."</script>" ?>
    

    as long as id is an existing html element id and $myresult is a php variable containing html

    OR

    You may try

    <div id="id"><?php echo $myresult; ?></div>
    

    Notes:
    1. It is getElementById() not getElementByID()
    2. Usually #id is used in jquery, and in pure JS it is just id

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制