如何在表单中提交div值 [英] how to submit a div value in a form

查看:147
本文介绍了如何在表单中提交div值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,就像checkbox.i想要在表单中提交它的value属性,但它不会传递给php文件。

p>

 < form action =test.phpmethod =post> 
< div id =test1value =testvaluename =testchecked =checked>< / div>
< input type =submit/>
< / form>

PHP:

 <?php 
$ test = $ _POST ['test'];
echo $ test;
?>


解决方案

只有表单元素被发回服务器。如果您想要发送值,您需要创建一个输入元素。您可以考虑制作< input type =hiddenname =testvalue =testvalue

为了响应您使用jQuery注释创建的自定义复选框,您可以使用jQuery来设置隐藏的输入元素的值。这将让你继续使用div,但有一个值被发送回服务器。


i have a div that acts like a checkbox.i want to submit its value attribute in a form but it wont pass to php file.

HTML:

 <form action="test.php" method="post">
    <div id="test1" value="testvalue" name="test" checked="checked"></div>
    <input type="submit" />
 </form>

PHP:

<?php
$test = $_POST['test'];
echo $test;
?>

解决方案

Only form elements are posted back to the server. You need to create an input element if you want the value sent. You could consider making an <input type="hidden" name="test" value="testvalue".

In response to your custom checkbox made with jQuery comment, you could use jQuery to set the value of the hidden input element. This will let you continue to use the div but have a value that gets sent back to the server.

这篇关于如何在表单中提交div值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆