【问题标题】:Bootstrap button not allowing onclick to pass in PHP variables引导按钮不允许 onclick 传递 PHP 变量
【发布时间】:2016-03-04 12:07:26
【问题描述】:

我有这样的代码,它是一个按钮,用于将用户重定向到具有特定auction_id 的特定项目的拍卖页面。该按钮的类型为<button>,我试图给它一个onclick以重定向到:

http://192.168.33.10/productpage.php?q=12344

但是我当前的代码使页面重定向到:

http://192.168.33.10/productpage.php?q=%3C?php%20echo%20$id;%20?%3E

任何想法为什么?代码如下,我在网上使用了解决方案,但对<button>标签没有帮助。

<td class="col-sm-1 col-md-1">
                            <?php
                            if ($_SESSION['role_id'] == 1 && $enddt > time()) {
                                $id = $bidauction['auction_id'];
                                echo '<button type="button" onclick="location.href=\'productpage.php?q=<?php echo $id; ?>\'" class="btn btn-success" style="margin-top:10px">
                                <span class="glyphicon glyphicon-hand-up"></span> Raise Bid
                                </button>';
                            }
                            ?>
                        </td>

【问题讨论】:

  • 你在 echo 语句中使用 标签。
  • 你为什么使用按钮标签?您应该根据您的要求使用锚标记并设置 href 属性。如果您想要设计的外观和感觉,那么您可以将 css 应用于锚标记。

标签: php twitter-bootstrap button


【解决方案1】:

试试这样:-

<td class="col-sm-1 col-md-1">
<?php
if ($_SESSION['role_id'] == 1 && $enddt > time()) {
    $id = $bidauction['auction_id'];
    echo '<a href="productpage.php?q='.$id.'" class="btn btn-success" style="margin-top:10px">
    <span class="glyphicon glyphicon-hand-up"></span> Raise Bid
    </a>';
}
?>
</td>

【讨论】:

    【解决方案2】:

    您正在 PHP 代码中编写一个 PHP 标记,我认为这没有必要, insted of writing , 就用

    ...'.$id.'...

    【讨论】:

      猜你喜欢
      • 2018-04-19
      • 2013-08-22
      • 1970-01-01
      • 2014-12-15
      • 2017-12-25
      • 2010-09-05
      相关资源
      最近更新 更多