http://www.practicalecommerce.com/blogs/post/438-The-Blurring-Line-Between-Plugins-and-Gems
Drop Down List URL Jump Box
Scenario: I have three web sites I want to link to. I also don't want to bore my friends by having them all lined up in a row, or in a long unordered list. I want them to click a little drop down box, and have that site automatically load.
To accomplish this, I need to use a blank form, and I need to place a selection list on it. I need to add options for each of the three sites, and then I need to do a little JavaScript magic.
Caution: Why do I need a form? Compatibility. Without the form surrounding the drop down list, some browsers will refuse to allow the JavaScript to work properly.
Form and List without JavaScript
<form name="jump1">
<select name="myjumpbox">
<option selected>Please Select...
<option value="http://www.davesite.com/">davesite.com
<option value="http://www.neonlollipops.com/">neonlollipops.com
<option value="http://www.about.com/">about.com
</select>
</form>
Okay, well, now all we need to do is politely ask the web browser software change the current page location (address) to the one selected when someone chooses something from the drop down box. We'll use the event OnChange.
<form name="jump1">
<select name="myjumpbox"
OnChange="location.href=jump1.myjumpbox.options[selectedIndex].value">
<option selected>Please Select...
<option value="http://www.davesite.com/">davesite.com
<option value="http://www.neonlollipops.com/">neonlollipops.com
<option value="http://www.about.com/">about.com
</select>
</form>
Feel free to try the jump box, and hit the back button to return to this page.
You are probably feeling a little like I did the first time I used this code. What does all of that line of gibberish mean?
OnChange="location.href=jump1.myjumpbox.options[selectedIndex].value"
Here's the simple explanation. OnChange is the event. location.href is the browser's current location. We are telling the browser to look at jump1 (our form), then look at myjumpbox on jump1 (our listbox), then figure out which of our options is selected, and then copy whatever value that option has into the browser's current location.
So if we choose davesite.com, the browser gets this:
location.href=http://www.davesite.com/
Cha-Ching. We're at davesite.com.
Note: If you're using frames, and you want the link selected to load in the entire window and not just inside the current frame, change location.href to top.location.href.
If we want to be slick, we can tell the browser to open the page into a new browser window.
<form name="jump2">
<select name="myjumpbox"
OnChange="window.open(jump2.myjumpbox.options[selectedIndex].value)">
<option selected>Please Select...
<option value="http://www.davesite.com/">davesite.com
<option value="http://www.neonlollipops.com/">neonlollipops.com
<option value="http://www.about.com/">about.com
</select>
</form>
It sure looks silly, but all jump2.myjumpbox.options[selectedIndex].value holds is the value of the currently selected drop down list item.
分享到:
相关推荐
gem_plugin-0.2.3.gem 的gem包
总结来说,"gem-maven-plugin-0.28.1.zip" 和 "jofilter.zip" 提供了一个Java项目管理和Ruby依赖集成的工具,以及一个用于网络过滤的开源解决方案。这两个项目都展示了开源软件在软件开发中的力量,允许开发者们利用...
实测可用
标题中的“rails飞信 gem plugin api 插件的问题解决方案”涉及到的是在Ruby on Rails框架下,使用特定的gem(一种Ruby的库或插件)来集成飞信API时遇到的问题及解决方法。飞信是中国移动推出的一种即时通讯服务,...
在压缩包子文件的文件名称列表中,`rspec-1.2.0.gem`和`rspec-rails-1.2.0.gem`是Ruby的gem包,这是Ruby的包管理器和依赖管理工具。每个`.gem`文件包含一个特定版本的rspec和rspec-rails插件,可以直接安装到Ruby...
【Max_UV_Plugin】是一款专为3D建模软件3ds Max设计的UV展开工具。在3D建模过程中,UV纹理坐标是至关重要的,它们决定了模型贴图的位置、大小和方向。这款插件以其简便的操作流程和对低版本3ds Max(2010及以下)的...
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
实测可用
这个Fluentd插件可以从RubyGems中以fluent-plugin-kinesis gem的形式获得。 gem install fluent-plugin-kinesis 或者您可以通过以下方式为安装此插件: td-agent-gem install fluent-plugin-kinesis 如果您想自己...
实测可用
实测可用
实测可用