我有一个 PHP 变量,我试图在不使用“值”属性的情况下出现在输入字段中,但我似乎无法让它工作。
我尝试了一个 jQuery 代码,我首先发现将变量“附加”到输入字段,但没有奏效。
    var first_name = "<?php echo $current_user['first_name']; ?>";
    alert(first_name);
    $('#first_name').val($('#first_name').val() + first_name);
然后我尝试使用 getElementById 但它也没有用。
    var first_name = "<?php echo $current_user['first_name']; ?>";
    alert(first_name);
    document.getElementById('first_name').value = first_name;
任何建议将不胜感激!
编辑:
这是 HTML 表单
<form name="personal_form" action="includes/editpersonal.php" method="POST">
   <fieldset>
      <legend><h2>Personal Details</h2></legend>
      <table class="personalform">
         <!--if there is an error on first name, the class name 'form_error_row' will be input into the following tr-->
         <!--allows me to colourise the text field to indicate an error on this row-->
         <tr class="<?php echo form_row_class("first_name") ?>" >
            <th><label for="first_name"><p>First Name: </p></label></th>
            <td>
            <input type="text" name="first_name" id="first_name" size="40" />
            <!--if there is an error it will print out a div with the error message-->
            <?php echo error_for('first_name') ?>
            </td>
          </tr>
      </table>  
   </fieldset>
   <input type="submit" class="reg-button" value="Update Records" />
</form>