jQuery导航到选择选项中的页面 [英] jQuery to navigate to page in select option

查看:100
本文介绍了jQuery导航到选择选项中的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个小片段,以允许用户根据选项选择控件中的用户选择转到新网址.

I am trying to write a little snippet that allows a user to go to i.e. navigate to) a new url, based on a user selection in an option select control.

<script type="text/javascript">
/* <[CDATA[ */
jQuery.noConflict();
jQuery(document).ready(function(){
    var id = jQuery($this).val();
    var url = some_Lookup_func(id);
    jQuery("#the_id").change(function () { /* how do I navigate the browser to 'url' ?*/ );
});
/* ]]> */
</script>

注意:这不是我想要的AJAX行为,我希望浏览器的行为就像您单击超链接一样.我以前做过,但是我忘记了怎么做.我看了一下jQuery文档,并且load()似乎没有做到这一点-因为我不想将内容放置在当前页面中-我想:

Note: This is not AJAX behaviour I want, I want the browser to behave as though you had clicked on a hyperlink. I have done this before, but I have forgotten how to do it. I had a look at the jQuery docs, and load() does not seem to do it - because I do not want to place the contents in the current page - I want to:

  1. 转到一个全新的页面
  2. 将参数传递到我要导航到的网址(例如,所选项目的ID

推荐答案

jQuery

var YourParam="sunshine";

$(document).ready(function() {
  $("#goto").change(function(){
    if ($(this).val()!='') {
      window.location.href=$(this).val()+"?param="+YourParam;
    }
  });
});

HTML

<form action="whatever.shtml" method="post" enctype="multipart/form-data">
  <select id="goto">
    <option value="">Go somewhere...</option>
    <option value="http://cnn.com/">CNN</option>
    <option value="http://disney.com/">Disney</option>
    <option value="http://stackoverflow.com/">stackoverflow</option>
    <option value="http://ironmaiden.com/">Iron Maiden</option>
  </select>
</form>

这篇关于jQuery导航到选择选项中的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆