使用php修改元素'

Change element's innertext with php

本文关键字:元素 php 修改 使用      更新时间:2023-09-26

我想改变一个元素的innerText使用php(我也使用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);