我正在尝试使用 PHP 脚本发送数据。我用jqCron我的问题是我有动态 SPAN 值,但该跨度的值没有使用 post 函数发送。我无法获取该值
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$TiData = !empty($_POST['BCTiData']) ? $_POST["BCTiData"] : '';
echo $TiData;
}
?>
这是表格
<form id="fo1" action="#" method="post">
<div class="timer"> </div>
<input type="text" class="form-control" id="BCTiData" name="BCTiData" value="<span class="timer-span"></span>">
</form>
我也尝试这个方法:
$degerSpan = '<span class="timer-span"></span>'; // Not working
如何获取Span中的数据以及如何使用POST发送? 谢谢
我也把它放在这里Pastebin
最佳答案
您需要使用javascript从SPAN元素中提取值,然后将其放入隐藏的表单字段中,然后提交数据。 这可以通过多种方式来完成。以下是一些可以帮助您入门的模型代码:
<!-- the Span that will contain the data we're interested in -->
<span class="cronMDMtimer-span"></span>
<!-- The HTML Form that will submit the timer value, this is populated using javascript -->
<form onsubmit="myFunction()" id="my-form">
<input type="hidden" name="timerValue" id="timerValue" value="not yet defined">
<input type="submit">
</form>
<script>
// This function gets called once the user submits the form
function myFunction(){
// First get the value from the cronMDMtimer-span
timerValue = $('.cronMDMtimer-span').html();
// Then store the extracted timerValue in a hidden form field
$("#timerValue").val(timerValue);
// submit the form using it's ID "my-form"
$("#my-form").submit();
}
</script>
关于javascript - 使用 POST 将动态 SPAN 值发送到 PHP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38999714/