【问题标题】:set a $_GET value when option is selected选择选项时设置 $_GET 值
【发布时间】:2015-05-30 07:34:23
【问题描述】:

在选择选项时,我将如何通过$ _get设置过滤器_branch = true和filter_branch_val =索尼?

<select name="filter_brand">
   <option>Sony</option>
   <option>LG</option>
</select>

所以我有类似 http://mypage.com/index.php?filter_branch=true&amp;filter_branch_val=sony 的东西用于 sql 查询过滤器。

【问题讨论】:

  • 当您想在选择框的更改事件中将值作为查询字符串发送?
  • @fireflieslive 我已经发布了一个工作代码,您还需要添加一个名为“no selection *”之类的新选项。否则您无法选择默认选项。如果您满意,请接受答案:)

标签: html get


【解决方案1】:

如果 java 脚本函数对你有用。请尝试此代码

HTML

<select name="filter_brand" onchange="sendFilter(this.value)">
 <option>Sony</option>
 <option>Lg</option>
 <option>Samsung</option>
</select>

JavaScript

<script type="text/javascript">
 function sendFilter(vaa)
 {
     console.log(vaa);
     window.location.href = 'product.php?  
     filter_branch_val='+vaa+'&filter_branch=true';
 }
</script>

【讨论】:

  • 您是否在 中添加了:&lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;&lt;/script&gt; &lt;/head&gt;
  • @GjertGjersund ,不,因为这里我只使用 java 脚本而不是 jquery
  • 另外,+vaa+ 在我的 IDE 中出现错误,但不知道为什么。当然。应该看到的。但是,我评论的帖子至少有效:)
  • 如果你想在工作中看到它,请访问:www.gogetit.no。我将代码添加到我的网站。
  • 我刚刚上传了我在这里发布的脚本。 azeezkallayi.com/demo/test/select.html 在这里工作正常
【解决方案2】:

您可以为此使用 jQuery。我已经对其进行了测试,并且可以正常工作。

添加这个:

<head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> </head>

HTML

<select id="myselect" name="filter_brand" onchange="javascript:goToURL()">
   <option>No selection *</option>
   <option>Sony</option>
   <option>LG</option>
</select>

脚本

<script>
function goToURL(url){
var option = $( "#myselect option:selected" ).text();
var yoururl = "http://www.example.com/";
var url = yoururl+ "?page="+ option;
window.location.replace(url);
}
</script>

试试这个然后回来找我。 我使用了ThisThis 作为参考。

【讨论】:

    猜你喜欢
    • 2012-10-31
    • 2011-10-27
    • 2012-09-12
    • 2021-11-26
    • 2015-07-08
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多