我有一个简单的 div 用于显示用户帐户信息,例如名字:
<div id="firstNameChange"><?=$firstName?></div>
我有用于将其转换为输入元素的 jquery 代码:
//execute when nameChange DIV is clicked
        $("#firstNameChange").click(function(){ 
                //check if there are any existing input elements
                if ($(this).children('input').length == 0){
                    $("#saveFirstName").css("display", "inline");
                    //variable that contains input HTML to replace
                    var inputbox = "<input type='text' class='inputbox' name='firstName' value=\""+$(this).text()+"\">";    
                    //insert the HTML intp the div
                    $(this).html(inputbox);         
                    //automatically give focus to the input box     
                    $("this .inputbox").focus();
                    //maintain the input when it changes back to a div
                    $("this .inputbox").blur(function(){
                        var value = $(this).val();
                        $("#firstNameChange").text(value);
                    });
                }               
        });
我创建了一个 PHP 变量来获取输入元素的内容,但它没有填充变量。出于某种原因,没有使用我在上面创建的 JS 输入元素的名称值设置该变量。任何想法为什么会这样?
if(isset($_POST['submit'])){
$firstName = $_POST['firstName'];
$sql = "UPDATE `user_accounts` SET `first_name`='$firstName' WHERE email='" . $_SESSION['email'] . "' AND user_id=" . $_SESSION['userID'] ;
$_dbConn->update($sql) or die(mysql_error());
Redirect_To('index.php?page=userProfile');  
}