donglanzhan7151 2013-07-18 21:18
浏览 61
已采纳

单击<li value = xx>时将值传递给php会话

ex.

<li value="123">123</li>
 <li value="456">456</li>

howto pass value <li value="xxx"> to a php session when clicking on <li value ="xxx">

  • 写回答

2条回答 默认 最新

  • dsa89029 2013-07-18 21:26
    关注

    You would create a file that looks like this

    // update_session.php
    
    <?php session_start(); 
    if (isset($_POST["val"])){
           $_SESSION["val"] = $_POST["val"];
    }
    

    Then for your html you would have (note I changed attribute to a data-value because value is not a valid attribute for li whereas the data- prefix attributes are valid.)

    <ul id ='my_ul'>
    <li data-value="123">123</li>
    <li data-value="456">456</li>
    </ul>
    

    And you jquery (in a document ready block) would look like this.

    $('#my_ul').on("click", "li", function(){
       $.ajax("update_session.php",{method:"post", data:{val:$(this).attr("data-value")}}); 
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?