【问题标题】:How to create button with a link, with variable如何创建带有链接的按钮,带有变量
【发布时间】:2023-04-04 06:34:01
【问题描述】:

我正在尝试创建将我重定向到另一个页面的按钮。 我正在尝试将变量放在链接中,但按钮不起作用。

这是我的脚本:

$idSelect[i]="SELECT * FROM times WHERE id=" . $mid[i] . "";
$idResult[i]=mysqli_query($con,$idSelect[i]); 

while($row = mysqli_fetch_array($idResult[i])) {
$uid[i]=$row['userid'];
}

$inc = "in.php?id=". $uid[i] ."";

echo "<input type='submit' value='back' class='button' onclick='window.location.href=". $inc ."'>";

注意事项:

  • ID 从数据库中打印 Int。
  • echo $inc 工作正常,我检查过了。

我尝试了一些教程,并阅读了相同问题的答案,但它们没有帮助

编辑:我认为我的错误与 onclick 位置有关,但我不知道是什么问题..

【问题讨论】:

  • 你可以尝试锚链接而不是按钮。
  • @BindiyaPatoliya 你是什么意思?
  • 你可以用type='button'代替type='submit'
  • @TunZarniKyaw 仍然无法正常工作
  • 如果您认为错误是 Javascript 错误,请检查您的浏览器控制台...您会看到错误是什么

标签: javascript php html button


【解决方案1】:

你没有附上链接。

所以你的 html 输出看起来像这样

<input type="submit" value="back" class="button" onclick="window.location.href=in.php?id=1"> 

所以 javascript 会寻找一个名为 in 的变量

这应该可以工作

echo "<input type='submit' value='back' class='button' onclick='window.location.href=\"". $inc ."\"'>";

【讨论】:

    【解决方案2】:

    你可以这样做。

    $inc = "http://in.yahoo.com/?p=us";
    echo "<input type='submit' value='back' class='button' onclick='redirect()'>";
    
    echo ("<script>
    function redirect(){
        window.location.href = '$inc';
    }
    </script>");
    

    【讨论】:

      【解决方案3】:

      嘿使用 onclick='window.location.replace' 如下-

      echo "<input type='button' value='back' class='button' onclick='window.location.replace="'. $inc .'"'>";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-23
        • 2021-04-11
        • 2020-01-18
        • 2012-07-27
        • 2019-05-26
        • 1970-01-01
        • 2014-02-14
        • 2012-05-15
        相关资源
        最近更新 更多