0

我正在尝试创建一个弹出窗口,其中包含一个包含输入的表单。有 2 个输入,在提交表单时,它应该从输入中获取值并将它们分配给变量,然后将其传递给 php 代码。我所做的任何事情似乎都没有得到分配的值。我尝试在 javascript 中输出变量,但它只是在单击按钮时重置文本框

   <?php
    include'../dbconnect.php';

    echo "in character creation";
    if(isset($_POST['name']) && isset($_POST['type']) ) {
        $name = $_POST['name'];
        $type = $_POST['type'];

        echo $name." ".$type;
    }

    ?>
    <html>
    <form id="frmNewChar">
    Character Name: <input type="text" id="charName"></input> <br />
    Character Type: <input type="text" id="charType" ></input> <br />
    <button id="btnNewChar" >Submit</button>
    </form>
    </html>

    <script language="JavaScript"><!--
    $("#btnNewChar").click(function(){
        var name = $("#charName").val;
        var type = $("#charType").val;
            $("#frmNewChar").before(name);
            // $.post(this, {name: name, type: type}, function(data){
                // text=data;
                        // elem = $("#frmNewChar");
                        delay=100;
                        // addTextByDelay(text,elem,delay);

                // });
    });
    //--></script>
4

1 回答 1

0

你的 Jquery 函数应该是这样的,

$("#btnNewChar").click(function(){
        var name = $("#charName").val();
        var type = $("#charType").val();
            $("#frmNewChar").before(name);
            // $.post(this, {name: name, type: type}, function(data){
                // text=data;
                        // elem = $("#frmNewChar");
                        delay=100;
                        // addTextByDelay(text,elem,delay);

                // });
    });

您使用了val而不是val()

于 2013-10-21T09:33:10.640 回答