使用Javascript / jQuery的 - 基于下拉选项转到网址 [英] Javascript / jQuery - Goto URL based on Drop Down Selections

查看:182
本文介绍了使用Javascript / jQuery的 - 基于下拉选项转到网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个下拉框和一个Go按钮。我需要到一个基于什么在3网址框中选择内置的URL - 这是我的code的例子

 <形式为GT;
  <选择类=下拉菜单ID =DD1的风格=保证金权:10px的; WIDTH:130px>
    <选项>的http://< /选项>
    <选项> FTP://< /选项>
    <选项>的https://< /选项>
  < /选择>
  <选择类=下拉菜单ID =DD2的风格=保证金权:10px的; WIDTH:130px>
    <选项>谷歌< /选项>
    <选项>雅虎和LT; /选项>
    <选项> BBC< /选项>
    <选项>的Hotmail< /选项>
  < /选择>
  <选择类=下拉菜单ID =DD3的风格=WIDTH:130px;保证金右:20px的>
    <选项>&.COM LT; /选项>
    <选项> .NET< /选项>
    <选项> .co.uk< /选项>
  < /选择>
  <输入类型=提交名称=按钮ID =按钮值=走!>
  < /表及GT;

因此​​,举例来说,如果用户选择的http:// +雅虎+ .NET - 然后打一个转到按钮,他们将被送往的 http://yahoo.net 或如果用户选择HTTPS // +的Hotmail + .COM然后它们被发送到的 https://hotmail.com

有一些jQuery或Javascript code,将在下拉菜单检测中的选择,然后建立正确的URL和GOTO它时,转到按钮是pressed?

谢谢
扎克


解决方案

  VAR D1 = $(#DD1)找到(:选择了)。ATTR(值 );
VAR D2 = $(#DD2)找到(:选择了)。ATTR(值);
VAR D3 = $(#DD3)找到(:选择了)。ATTR(值);location.href = D1 + D2 + D3 +;

I have 3 drop down boxes and a go button. I need to goto a URL that is built based on what is selected in the 3 URL boxes - here is an example of my code.

  <form>
  <select class="dropdown" id="dd1" style="margin-right:10px;width:130px">
    <option>http://</option>
    <option>ftp://</option>
    <option>https://</option>
  </select>
  <select class="dropdown" id="dd2" style="margin-right:10px;width:130px">
    <option>google</option>
    <option>yahoo</option>
    <option>bbc</option>
    <option>hotmail</option>
  </select>
  <select class="dropdown" id="dd3" style="width:130px;margin-right:20px">
    <option>.com</option>
    <option>.net</option>
    <option>.co.uk</option>
  </select>
  <input type="submit" name="button" id="button" value="Go!">
  </form>

So, for example, if a user selects http:// + yahoo + .net - then hits a "Go" button, they would be sent to http://yahoo.net or if the user selects https// + hotmail + .com then they are sent to https://hotmail.com

Is there some jQuery or Javascript code that would detect the selections from the dropdowns, then built the correct URL and goto it when the "Go" button is pressed?

Thanks Zach

解决方案

var d1 = $("#dd1").find(":selected").attr("value");
var d2 = $("#dd2").find(":selected").attr("value");
var d3 = $("#dd3").find(":selected").attr("value");

location.href = d1+d2+d3+"";

这篇关于使用Javascript / jQuery的 - 基于下拉选项转到网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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