我遇到过this nifty little function,用JavaScript添加隐藏的输入字段到HTML表单。将输入字段添加到HTML表单中的JavaScript函数不清
下面的代码:
function addHidden(theForm, key, value) {
// Create a hidden input element, and append it to the form:
var input = document.createElement('input');
input.type = 'hidden';
input.name = key;'name-as-seen-at-the-server';
input.value = value;
theForm.appendChild(input);
}
// Form reference:
var theForm = document.forms['detParameterForm'];
// Add data:
addHidden(theForm, 'key-one', 'value');
addHidden(theForm, 'another', 'meow');
addHidden(theForm, 'foobarz', 'baws');
// Submit the form:
theForm.submit();
我不明白的是在input.name = key;'name-as-seen-at-the-server';
的'name-as-seen-at-the-server'
。
这个集合究竟是什么,它是如何使用的?
在给出的上下文(将输入附加到DOM的函数)中,它没有任何作用。密钥可以是任意确定的字符串。 – zer00ne
我把它运行在jsfiddle和“在服务器上看到的名字”;'什么都不做。然后将值'key'分配给左侧的变量。 – Ayush
注释名称在服务器上看到或删除它,它只是你的字段名称。没有其他 –