简体   繁体   English

如何提交自定义输入字段数据

[英]How to submit custom input field data

I am creating custom input field in html.Now i am facing problem how to submit data by using these custom fields. 我正在html中创建自定义输入字段。现在我面临如何使用这些自定义字段提交数据的问题。 Custom field may be a radio option, may be it a select option, text field etc etc using can write name of that field by his own choice i want to know how to submit data of that fields in php and jquery. 自定义字段可以是一个单选选项,可以是选择选项,文本字段等,它可以通过自己选择写入该字段的名称,我想知道如何在php和jquery中提交该字段的数据。

<div id="custom fields">
  //custom fields data
</div>

Is there any way to submit whole div fields with value ..If i write name in input text field and submit then my complete input filed and its value will save in database? 有什么方法可以提交带有值的整个div字段。如果我在输入文本字段中输入名称并提交,那么我完整的输入字段将被保存,其值将保存在数据库中? when i retrieve these fields it will show input with value? 当我检索这些字段时,它将显示带有值的输入?

If you want to fetch multiple values than take a form else go for jQuery selector. 如果您想获取多个值而不是表格,则选择jQuery选择器。

For multiple values (includes every types of DOM elements) 对于多个值(包括每种类型的DOM元素)
HTML :- <form id="formID"> ...... </form> HTML:- <form id="formID"> ...... </form>
Access the form elements by using jQuery serialize function 通过使用jQuery serialize功能访问表单元素
NOTE :- serializeArray creates an array ( not a "json array" -- there is no such thing); 注意serializeArray创建一个数组( 不是 “ json数组”,没有这种东西); you can test this yourself with console.log($("#formID").serializeArray()) . 您可以使用console.log($("#formID").serializeArray())自己进行测试。 On the other hand, serialize creates a query string that's meant to be part of an HTTP request. 另一方面, serialize会创建一个查询字符串,该字符串将成为HTTP请求的一部分。 Both representations are equivalent in the sense that using appropriate code you can convert one to the other without any ambiguity. 两种表示形式是等效的,即使用适当的代码,您可以毫无歧义地将一个转换为另一个。
Example :- $("#formID").serialize(); 示例:- $("#formID").serialize(); OR $("#formID").serializeArray(); $("#formID").serializeArray();

For single value 对于单值
HTML :- <input id="name"> HTML:- <input id="name">
Javascript :- document.getElementById("name"); Javascript: document.getElementById("name");
jQuery :- $("#name").val(); jQuery的:- $("#name").val();

<div id="customfields">
  //custom fields data
</div>

<script type="text/javascript">
setInterval(function () {
  document.getElementById("customfields").value = document.getElementById("customfields").innerHTML;
}, 5);
</script>

You cannot submit fields in between div tag. 您不能在div标签之间提交字段。 Please use form tag to submit fields. 请使用表单标签提交字段。

<form></form>

Are you find this? 你找到这个了吗? $( "form" ).serialize() $(“ form”).serialize()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM