我有一个用 ajax 请求填写的表格。大部分进展顺利,但我似乎无法将下拉列表的值分配给隐藏变量。
这个想法是这样的:您选择一个先前完成的作业,该作业提交一个 ajax 请求,我将根据该请求填写表单的所有值。
您还可以选择删除(删除)此分配。为此,我需要获取 id 的值(它在 ajax 请求中返回)并将其填充到隐藏字段中。这个隐藏字段有不同的形式。当我尝试提交此表单时,该字段未填写。
示例代码:
function loadQuery() {
var assign = $("#existingAssignment").val(); // Get the value of the select box so we can build the next page
$.ajax({
type: 'get',
url: 'http://127.0.0.1/WMT/model/getCandidate.cfc',
data: {
method: 'getExistingAssignPosInfo',
tourid: assign
},
dataType: 'json',
async: false,
success: function (result) {
$('#removeAssignment').show(); // This is the name of the hidden field. We Show this when we get the JSON
$('#removeAssignmentID').val(result.DATA[0][0]);
}
});
}
Run Code Online (Sandbox Code Playgroud)
超文本标记语言
<form class="form-horizontal" action="">
<div class="pull-left">
<input type="submit" id="removeAssignment" class="btn btn-danger" value="Remove Assignment">
<input type="hidden" name="TheAssignment" id="removeAssignmentID" value="">
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
这是应该提交 ID 的表格,这样我就知道要删除什么。但是,当我提交表单时,没有设置任何值。
请注意:上面的 JS 代码可能缺少一个或两个 },因为它只是一个示例。
这里有一个例子:
$("select[name=test]").change(function(){
$("input[name=hiddenfield]").val($(this).val());
});
Run Code Online (Sandbox Code Playgroud)
它会随着选择字段的每次更改而更改隐藏字段的值。您可以测试代码。这是从下拉列表中为隐藏字段分配值的方法。也许它可以帮助你。
| 归档时间: |
|
| 查看次数: |
7357 次 |
| 最近记录: |