繁体   English   中英

用php更改元素的innertext

[英]Change element's innertext with php

我想使用php更改元素的innerText(我也使用jquery); 我试过这个:

<?php
    $variable = "Hello";
    echo '<script>$('#element').text($variable);</script>'
?>

但它没有用。 我也尝试过:

document.getElementsById('element').innerText = $variable;

您有上述评论中提到的@Robiseb报价问题,请使用:

echo "<script>$('#element').text('" . $variable . "');</script>"
//Or
echo "document.getElementsById('element').textContent = '" . $variable . "';"

希望这可以帮助。

采用

 document.getElementById('element').innerHTML = $variable;

要么

$('#element').html($variable);

暂无
暂无

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

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