Javascript 如何在php变量中获取div的文本,而其文本来自js函数

Javascript 如何在php变量中获取div的文本,而其文本来自js函数,javascript,php,jquery,Javascript,Php,Jquery,这是我的模式代码 <p id="getdatevalue" style="display:none;"></p> //HOW TO GET THIS DIV TEXT IN PHP </div> //如何在PHP中获取此DIV文本 我在这个锚标签中得到php的日期 <?php for($i = 1; $i <= $this->daysInCurrentMonth + $this->firstDayOfTheWeek; $i

这是我的模式代码

   <p id="getdatevalue" style="display:none;"></p> //HOW TO GET THIS DIV TEXT IN PHP

</div>

//如何在PHP中获取此DIV文本
我在这个锚标签中得到php的日期

<?php
for($i = 1; $i <= $this->daysInCurrentMonth + $this->firstDayOfTheWeek; $i++) {
    ?><a href="#" id='<?php echo $dataVal; ?>' class="testclass">SetRecipe</a>
    <?php
    $day++;
}
?>

单击此链接即可打开模式窗口

我在一些div中以id的形式传递日期,在单击testclass时获得相同的id,这意味着我在通过lope填充的id中获得了日期值(假设2014年4月27日)

<script>
    $(".testclass").click(function(event) {
                    var date_value = $(this).attr("id");
                    $("#getdatevalue").html(date_value);
    });
</script>

$(“.testclass”)。单击(函数(事件){
var date_value=$(this.attr(“id”);
$(“#getdatevalue”).html(日期值);
});
使用


$(“.testclass”)。单击(函数(事件){
var date_value=$(this.attr(“id”);
$(“#getdatevalue”).html(日期值);
$.post('aPhpFile.php'{
dateVal:$(“#getdatevalue”).html()
});
//因为你特别问过如何从中获得价值
//元素,但$.post('aPhpFile.php',{dateVal:date_value});
//好的
});
和php(aPhpFile.php)


是否要使用PHP生成div文本?或者你想让PHP服务器获取该div的内容?我想将div的文本保存在PHP变量中,即当我打开modal时,我会获取存储在PHP变量中的当前数据(该div的id)。一般来说,正如andrew在下面的回答中所说,将客户端值保存到服务器变量中。但是您最好在客户端进行所有客户端计算。
<script>
    $(".testclass").click(function(event) {
                    var date_value = $(this).attr("id");
                    $("#getdatevalue").html(date_value);
                    $.post('aPhpFile.php',{
                      dateVal: $("#getdatevalue").html()
                       });
                   // since you specifically asked how to get the value from that
                   //  element, but $.post('aPhpFile.php',{dateVal:date_value});
                   // would be fine
              });
  </script>
 <?php
 $postedVal = $_POST['dateVal'];