我有一个div形式,我尝试使用value.php中的$ _POS [' calander']将值发布到另一个php,但它只返回空白, 如何从另一个PHP获取div值?
<form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" action="value.php" method="post">
<div id="calander" class="pull-left" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
<i class="glyphicon glyphicon-calendar fa fa-calendar" id="reportrange_right"></i>
<span> </span> <b class="caret"></b>
</div>
</form>
如何将div值发布到另一个php?
答案 0 :(得分:0)
你可以用它来帮助你,
<form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" action="value.php" method="post">
<div id="calander" class="pull-left" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
<i class="glyphicon glyphicon-calendar fa fa-calendar" id="reportrange_right"></i>
<span> </span> <b class="caret"></b>
</div>
<input type="hidden" id="hiddeninput" name="hiddeninput">
<input type="submit" id="subs" name="subs" value="Submit"/>
</form>
<script>
$(function(){
$('#subs').click(function () {
var mysave = $('#calander').html();
$('#hiddeninput').val(mysave);
});
});
</script>
在PHP
页面使用
$_POST['hiddeninput'];
接收值
答案 1 :(得分:0)
发送表单数据仅适用于输入元素!所以你需要创建输入元素来做到这一点。如果你了解jQuery,可以通过ajax方法轻松制作。这是我试过的Javascript <form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" action="value.php" method="post" onclick="Send(this)">
<div id="calander" class="pull-left" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
<i class="glyphicon glyphicon-calendar fa fa-calendar" id="reportrange_right"></i>
<span> </span> <b class="caret"></b>
</div>
</form>
<script type="text/javascript">
function Send(t) {
var data = document.getElementById('calander');//get div element
var divinput = document.createElement("input");//create new input
divinput.setAttribute('type', 'hidden'); //type hidden
divinput.setAttribute('name','calander'); //set post name
divinput.setAttribute('value', data.innerHTML);//send div value(html)
t.appendChild(divinput); //You must append current form before submit
t.submit();
return false;
}
</script>
示例....
l = f.readline()[brk + 2]