简体   繁体   English

如何将span标签的值放在php变量中

[英]How to put value of span tag in php variable

I have <span id="count"></span> which is basically changing its value on click. 我有<span id="count"></span> ,它基本上是在点击时更改其值。

Part of my javascript code is 我的JavaScript代码的一部分是

$( document ).ready(function() {

  $('#stars').on('starrr:change', function(e, value){
    $('#count').html(value);
  });      

});

How to store the value of id count in a variable in php. 如何将ID计数的值存储在php中的变量中。

I tried: 我试过了:

<?php $var = ?><span id="count"></span><?php ; ?>

But I am getting error. 但是我遇到了错误。

I cant store it in hidden field because its value changing on click. 我无法将其存储在隐藏字段中,因为单击时其值会发生变化。

Is there a way such that When I click a "Post" button whatever the value of #count it get stored it in php variable so I can insert into database. 有没有一种方法,当我单击“发布”按钮时,无论#count的值是多少,它都会将其存储在php变量中,因此我可以将其插入数据库。

Thanks. 谢谢。

JavaScript is client side and PHP is server side JavaScript是客户端,PHP是服务器端

You must send your value to server with ajax 您必须使用ajax将值发送到服务器

$(document).ready(function() {
    $('#stars').on('starrr:change', function(e, value) {
        $('#count').html(value);
        $.ajax({
            url: "saveVariable.php",
            data: {value:value}
        }).done(function() {

        });
    });

});

saveVariable.php saveVariable.php

$var=$_REQUEST["value"];

Try like this... 这样尝试...

$value = "<script type='text/javascript'> $('#count').html();</script>"; ?>
echo $value;

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

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