jquery tokeninput 中未定义的错误


Undefined error in jquery tokeninput

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

在演示中,当我单击提交按钮时,它会发出警报:"将提交:"和值。我在我的身上做了同样的事情,它提醒:"would submit: undefined"

我的表格.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>

html 中没有此处指定的input[type=text]元素:

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

将您的 html 更改为:

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