gpt4 book ai didi

javascript - 为什么 BootStrap TokenField 输入未在 POST 请求中传递?

转载 作者:行者123 更新时间:2023-12-03 01:40:08 25 4
gpt4 key购买 nike

我正在使用http://sliptree.github.io/bootstrap-tokenfield/让用户选择多个关键字并通过 Django 中的 post 请求提交。下面是一段代码:

<!DOCTYPE html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet">

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tokenfield/0.12.0/bootstrap-tokenfield.min.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tokenfield/0.12.0/css/bootstrap-tokenfield.css" />

</head>

<body>
<form action="/lol" method="POST">
<input type="text" class="form-control" id="keyword" value="red,green,blue" />
<button class="btn btn-primary"> <span class="glyphicon glyphicon-upload" style="margin-right:5px;"></span>Submit Values</button>
</body>

<script>
$('#keyword').tokenfield({
autocomplete: {
source: ['red','blue','green','yellow','violet','brown','purple','black','white'],
delay: 100
},
showAutocompleteOnFocus: true
})
</script>
</html>

假设我将输入文本中的值填充为 red greenblue 并点击提交。很可能,它应该向 /lol 端点发出 POST 请求,并提交 keyword= 参数下的值。但这不起作用。

token 字段库有问题吗?如何发出用户输入值的发布请求?

最佳答案

您需要为输入元素分配一个名称属性。没有名称的表单元素不会包含在请求中。

以下内容将起作用,

<input type="text" class="form-control" name="keyword" id="keyword" value="red,green,blue" />

W3C 规范要求每个表单输入元素都指定一个名称属性。否则,该元素将不会被处理。 Source

关于javascript - 为什么 BootStrap TokenField 输入未在 POST 请求中传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50883810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com