如果我有一些PHP HTML,如下所示:
<html> I am feeling <?php print urldecode($_GET["emotion"]);?> today!</html>
Run Code Online (Sandbox Code Playgroud)
在URL标题中获取"情感"是"快乐",HTML呈现"我今天感觉快乐!".
现在,从PHP迁移,我如何用javascript做到这一点?
在Javascript中我有一个变量,$emotion = "Happy";所以Javascript在下面的脚本标签之间(当前有星号********)
<html> I am feeling <script>*********************</script> today!</html>
Run Code Online (Sandbox Code Playgroud)
您可以通过将元素放在要更改文本的位置,然后通过它的id访问该元素来轻松完成.
$emotion = "Happy";
var e = document.getElementById('emotion');
e.innerHTML = $emotion;Run Code Online (Sandbox Code Playgroud)
I am feeling <span id="emotion"></span> today!Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
99 次 |
| 最近记录: |