Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript Void 0作为HREF传递PHP变量?_Javascript_Php_Html - Fatal编程技术网

使用Javascript Void 0作为HREF传递PHP变量?

使用Javascript Void 0作为HREF传递PHP变量?,javascript,php,html,Javascript,Php,Html,我正在创建一个允许用户编辑用户的页面。该表给出了下面显示的按钮中的行ID。当它直接指向另一个脚本时,它可以正常工作。但是,我想动态地打开这个程序所做的用户详细信息 虽然我不知道把$row放在哪里才能让页面访问它?我的研究更多的是在两个程序之间传递信息,而我只需要将它们连接起来 我只想在按下按钮时,将$row['usersid']变量发送到我可以使用的页面 编辑:看来我把自己和你们都弄糊涂了。如果可能的话,我想把它保存在PHP中。我所需要的只是$row['usersid']或一个存储它的变量,它目

我正在创建一个允许用户编辑用户的页面。该表给出了下面显示的按钮中的行ID。当它直接指向另一个脚本时,它可以正常工作。但是,我想动态地打开这个程序所做的用户详细信息

虽然我不知道把$row放在哪里才能让页面访问它?我的研究更多的是在两个程序之间传递信息,而我只需要将它们连接起来

我只想在按下按钮时,将$row['usersid']变量发送到我可以使用的页面

编辑:看来我把自己和你们都弄糊涂了。如果可能的话,我想把它保存在PHP中。我所需要的只是$row['usersid']或一个存储它的变量,它目前在PHP中。发送到页面而不刷新

echo "<td><a href='javascript:void(0);' onClick=".$row['usersid']."' id='showButton'><span class='glyphicon glyphicon-edit'></span></a></td>";

echo "<td><a href='javascript:void(0);'".$row['usersid']."' id='showButton'><span class='glyphicon glyphicon-edit'></span></a></td>";
echo”“;
回声“;

有很多方法可以将页面中的信息传递给另一个页面,让我列出其中一些方法:

  • 接近
  • 如您所见,我添加了一个
    数据用户id
    属性,该属性包含来自php的真实
    用户id
    ,因此在Javascript中可以执行以下操作:

    document.getElementById("showButton").addEventListener("click", function(){
    var userId = this.getAttribute("data-user-id");
    // here you can call your ajax ...
    }, false);
    

    我希望这对您有用。

    如果您想检查您的值,请使用此代码获取您的值

    您还可以使用此代码获取数据

      <?php 
          $row['usersid'] = 10; // fot test case 
          $row['usersid1'] = 13; // fot test case 
          ?>
            <script type="text/javascript">
            $(document).on('click', '.getValue', function(){
                // send data to PHP
                var id = this.getAttribute("userId");
                alert(id)
            });
    
            </script>
        <?php
        echo "<td><a href='javascript:void(0);' class = 'getValue' userId = ".$row['usersid']." id='showButton'>Button</a></td>";
        echo "<br>";
        echo "<td><a href='javascript:void(0);' class = 'getValue' userId = ".$row['usersid1']." id='showButton'>Button</a></td>";
    
    
    $(文档).on('单击','.getValue',函数(){
    //将数据发送到PHP
    var id=this.getAttribute(“userId”);
    警报(id)
    });
    
    显示您的代码以及您面对的部分problem@ShafiqulIslam请原谅,我不习惯它如何格式化代码。我将它放在href和onclick中,但没有传递变量,因为您使用的是PHP,所以可以将其作为GET变量发送。例如
    echo”“是否要使用此值链接其他页面?echo“函数测试(x){alert(x);}”;更改onClick=“.test(“.”$row['usersid']”.“)Alexander O'Mara感谢您编辑答案,我在代码编辑器中遇到了一些问题。希望它能帮助您将非标准属性添加到html元素不是最佳做法,
    dataset
    属性是为此类用例设计的,因此我建议使用它,而不是像
    userid
    这样的随机属性
    document.getElementById("showButton").addEventListener("click", function(){
    var userId = this.getAttribute("data-user-id");
    // here you can call your ajax ...
    }, false);
    
      <?php 
          $row['usersid'] = 10; // fot test case 
          $row['usersid1'] = 13; // fot test case 
          ?>
            <script type="text/javascript">
            $(document).on('click', '.getValue', function(){
                // send data to PHP
                var id = this.getAttribute("userId");
                alert(id)
            });
    
            </script>
        <?php
        echo "<td><a href='javascript:void(0);' class = 'getValue' userId = ".$row['usersid']." id='showButton'>Button</a></td>";
        echo "<br>";
        echo "<td><a href='javascript:void(0);' class = 'getValue' userId = ".$row['usersid1']." id='showButton'>Button</a></td>";
    
            <script type="text/javascript">
            function getValue(value){
                alert(value)
            }
    
            </script>
        <?php
        echo "<td><a href='javascript:void(0);' onClick=getValue(".$row['usersid'].") id='showButton'>Button</a></td>";