How to embed php in HTML attribute?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-24 11:34:16
0
1
676

For example, I have a page where php and html are mixed together, and a variable is stored in the php part:

$class = "active";

In HTML I want to use this variable in the attribute of an element:

<p class="">helloworld</p>

For example, here I want to make the value of class of this p be active, which is just stored in the $class variable in php String.
what should I do then? Does JavaScript need to be used?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
阿神

This is implemented in the PHP stage. It is impossible for the JavaScript code to read the value of the PHP variable.

<?php
……
$class = 'active';
……
?>
<html>
<head>……</head>
<body>
……
<p class="<?=$class?>">helloworld</p>
……
</body>
</html>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template