PHP在选择标签中单击选项可单击的链接

发布于 2025-02-10 12:16:29 字数 587 浏览 2 评论 0原文

我正在尝试在“选择标签可单击的链接”中进行选项,但是在浏览器重定向到它从MySQL数组中获得的第一个值之前,我无法单击任何内容。

<select name="recipient" class="form-select form-select-lg mb-3"id="choice" onchange="location.href=this.value">
<?php 
foreach($all_users as $user):
 ?>
<option selected='' value="<?=$user['id']; ?>"><?= $user['firstname'] . ' ' . $user['lastname']; ?>
</option>                                   
<?php endforeach; ?>
</select>

ScreenShot

I'm trying to make the options in the select tag clickable links, but I'm not able to click anything before the browser redirects to the first value it gets from the mysql array.

<select name="recipient" class="form-select form-select-lg mb-3"id="choice" onchange="location.href=this.value">
<?php 
foreach($all_users as $user):
 ?>
<option selected='' value="<?=$user['id']; ?>"><?= $user['firstname'] . ' ' . $user['lastname']; ?>
</option>                                   
<?php endforeach; ?>
</select>

screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯沦落人 2025-02-17 12:16:29

我不确定,您的问题到底是什么,但是请尝试我的代码,希望您会得到一些东西

<select id="select-opt">
    <option value="https://www.google.com/">Google</option>
    <option value="https://www.facebook.com/">Facebook</option>
    <option value="https://www.youtube.com/">Youtube</option>
</select>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script type="text/javascript">
     $(document).on('change', '#select-opt', function (e) {
        var value = $(this).val();
        window.location.href=value;
    });
</script>

I am not sure, what is your question exactly, but try my code hopefully you will get something

<select id="select-opt">
    <option value="https://www.google.com/">Google</option>
    <option value="https://www.facebook.com/">Facebook</option>
    <option value="https://www.youtube.com/">Youtube</option>
</select>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script type="text/javascript">
     $(document).on('change', '#select-opt', function (e) {
        var value = $(this).val();
        window.location.href=value;
    });
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文