【问题标题】:Select box Onchange: autosubmit() option with php选择框 Onchange:带有 php 的 autosubmit() 选项
【发布时间】:2013-05-30 01:38:34
【问题描述】:

所以就像我有一个选择框,带有while循环作为选项,因为我想从数据库中取出选项,是否可以单击选项和链接?

while循环是这样的

while ($row = mysqli_fetch_assoc($result0))
{
$option .= '<option value="'.$row['id'].'">'.$row['Font_Family'].'</option>';
}

这是选择框

<select id='font' style="width:100px;" onchange="autosubmit();">
            <option value ="0">Select</option>

但是在点击我想将其链接到的选项时

 font.php?id={id that is being pointed to}

我该怎么做?

【问题讨论】:

  • 使用 Javascript 并创建“自动提交”功能。对 getElementById('font').value 的简单 window.location 更改将使您开始。
  • 选择元素不是链接,您需要使用 javascript,即使在 javascript 中,选项的点击处理程序也存在问题,您可能应该将某些内容绑定到 select 的 change 事件.

标签: php html hyperlink option drop-down-menu


【解决方案1】:

使用Javascript调用onchange。

在标题标签之间,放:

  <script type="text/javascript">
    function autosubmit() {
      window.location="font.php?id="+document.getElementById("font").value;
    }
  </script>

查看工作的jsbin:http://jsbin.com/uwuyoz/1/

请注意,您必须取消对 window.location 的注释。我现在只是让它'警报'。但是所有的代码都在那里。

【讨论】:

  • @SpeXial 没问题。不要忘记投票并选择答案:)
猜你喜欢
  • 2013-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多