gpt4 book ai didi

html - 标签如何影响表单提交
转载 作者:太空狗 更新时间:2023-10-29 14:38:32 25 4
gpt4 key购买 nike

请举例说明如何在 HTML 表单中使用对象标签。

我今天在阅读 HTML5 规范以了解现在存在什么样的表单元素,并注意到以下内容:

Submittable elements

Denotes elements that can be used for constructing the form data set when a form element is submitted: button, input, keygen, object, select, textarea http://www.w3.org/html/wg/drafts/html/master/forms.html#category-submit

很明显,一个表单可以有一个对象标签,影响表单提交时发送的数据。我熟悉对象标记的唯一上下文是将 Flash 电影嵌入页面。您可以在表单中使用对象标签并使其影响表单提交数据的示例情况是什么?

更新:

在关于如何在提交时构建表单有效负载的规范中,在 http://www.w3.org/html/wg/drafts/html/master/forms.html#constructing-form-data-set 中找到了这个有趣的片段

If the field element is an object element: try to obtain a form submission value from the plugin, and if that is successful, append an entry to the form data set with name as the name, the returned form submission value as the value, and the string "object" as the type.

但我想知道什么样的插件会分发这样的提交值。

更新:

QtBrowserPlugin 似乎支持在表单中使用它们。现在,我只需要一个这样的简约插件即可作为示例。

http://doc.qt.digia.com/solutions/4/qtbrowserplugin/developingplugins.html#using-plugins-in-forms

最佳答案

起初我建议使用最新的 HTML5 文档,网址为 http://www.w3.org/html/wg/drafts/html/CR/forms.html#constructing-form-data-set而不是 HTML5.1。

恐怕目前没有浏览器实现这种行为。在任何情况下,如果您想模仿规范所说的内容,您可以使用如下脚本:

<!DOCTYPE html>
<html>
<body>
<form method="post" action="index.html" id="myForm">
<input type="text" id="myFieldID" name="myFieldName" value="Hello World!" />
<object type="myPluginMIMETYPE" id="myPluginID" name="myPluginName" ></object>
<button type="submit">Submit</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
$( document ).ready(function() {
$( myForm ).on( "submit", function( event ) {
//Ask the plugin for some data, i.e. a flash object
var pluginData = "pluginImportantData"; // ideally something like $(myPluginID).giveMeSomeDataBecauseUserWantsToSubmit();
//Append the data before submission, giving to the input tag the right attributes
$(this).append('<input type="object" name="myPluginName" value="'+ pluginData +'" style="visibility:hidden"/>');
return true;
});
});
</script>
</body>
</html>

关于html - <object> 标签如何影响表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19176261/

25 4 0