drgawfsf1069 2016-04-03 06:01
浏览 26

如何将javascript值传递给php变量[重复]

This question already has an answer here:

 function myfun(){

    var texteld= document.getElementById('texteld').value;

    <?php

     $id =  "<script>texteld</script>";

 }

This PHP and JavaScript code does not working. i want to pass java script texteld value to PHP $id

</div>
  • 写回答

2条回答 默认 最新

  • dsafew1231 2016-04-03 06:08
    关注

    To Answer your question, you need to understand how a page loads:

    1. Request to server.
    2. Server Processes request, load pages, run php, whatever needs to be done.
    3. Server outputs html,css,javascript, whatever the process from 2 tells it to.
    4. Finally, your browser interprets all the data and gives you a layout.

    So, as you can see, php is run before javascript is even sent to the browser to be run. What you want to do is go backwards in the process, this is not possible.

    After the page loads and the browser has some data, you can send data back to php. This is not the same as your attempt though. You may need to rethink your strategy.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算