简体   繁体   English

设置由 php 回显的 div 的 innerhtml

[英]Set innerhtml of a div echoed by php

I created a div element using php echo我使用 php echo 创建了一个 div 元素

*//some html code*
*<?php echo "<div id = "randomDiv"></div>" ?>
<script>
     document.getElementById("randomDiv").innerHTML = "Hey";
</script>*

but this does not manipulate the innerHTML of the div.但这不会操纵 div 的 innerHTML。 Any ideas how to resolve this?任何想法如何解决这个问题?

Double quote for div id makes it invalid. div id的双引号使其无效。 Try changing the quote to single quote:尝试将引号更改为单引号:

<?php echo "<div id='randomDiv'></div>"; ?>
<script>
     document.getElementById("randomDiv").innerHTML = "Hey";
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM