dtlhy0771 2016-10-17 05:21
浏览 17
已采纳

将元素的文本指定为php变量

i have a text inside an element. This text will changed according to a jQuery. As it changes, I need to pull that text as a php variable. This variable will be used later in the same document.

<div id="divId">sometext<div>

now, I want to assign a php code to assign "sometext" as the variable

I need the below;

    <div id="divId">
    sometext
    <?php
    $variable = (get text from "divId");
    ?>
    <div>

then I can use it somewhere else like

<div>
<?php
if($variable == "sometext")
{
echo ($variable);
}
?>
<div>

I need help on the (get text from "divId")part

  • 写回答

1条回答 默认 最新

  • doujuan9698 2016-10-17 05:48
    关注

    You cant do with PHP. please use javascript or jquery

    please find way of jquery

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        var getDivValue = $('#divId').html();
        if(getDivValue == 'sometext'){
            $('#divId').html('updateText');
        }else if(getDivValue == 'other'){
             $('#divId').html('updateTextTwo');
        }
    });
    </script>
    </head>
    <body>
    <div id="divId">sometext</div>
    
    </body>
    </html>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向