【问题标题】:Undefined error in jquery tokeninputjquery tokeninput 中的未定义错误
【发布时间】:2015-03-15 15:13:21
【问题描述】:

jQuery tokeninput 返回 null 值。当我提交表单时,$_POST[] 数组为空。

demo 中,当我单击提交按钮时,它会发出警报:“将提交:”和值。我在我的也做了同样的事情,它提醒:"would submit: undefined".

我的 form.html :

<html>
<head>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript" src="jquery.tokeninput.js"></script>
<link rel="stylesheet" href="token-input-facebook.css" type="text/css" />
<script type="text/javascript">
    $(document).ready(function() {
        $("input[type=button]").click(function () {
            alert("Would submit: " + $(this).siblings("input[type=text]").val());
        });
    });
    </script>

</head>
<body>
<form action="process.php" method="post">

                            <label for="title" class="control-label col-sm-2">Title(s) :</label>
                                <input name="title" id="title" class="form-control">
                                <input type="button" value="Submit" />
                                <script type="text/javascript">
        $(document).ready(function() {
            $("#title").tokenInput("gethint.php", {
                theme: "facebook",
                hintText: "Begin typing title ...",
                noResultsText: "No titlesfound",
                propertyToSearch: "title",
                tokenValue: "'id'",
                tokenDelimiter: ","
            });
        });
        </script>
</form>

</body>
</html>

进程.php:

<?php
$titles = $_POST["title"];
?>
<html>
<body>
<?php
print_r($names);
?>
</body>
</html>

【问题讨论】:

    标签: php jquery jquery-tokeninput


    【解决方案1】:

    您的 html 中没有 input[type=text]elements,如下所示:

    alert("Would submit: " + $(this).siblings("input[type=text]").val());
    

    将您的 html 更改为:

    <input type="text" name="title" id="title" class="form-control">
    

    【讨论】:

    • 哇,我怎么错过了? :) 谢谢
    • @DrZIZO - 很容易做到;)如果它对你有用,你能把它标记为答案吗?
    • 我必须等待 4 分钟才能接受您的回答
    猜你喜欢
    • 2012-08-16
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多