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.
分享到:
相关推荐
实训商业源码-深蓝健身房瑜伽馆行业小程序V4.5.0全开源解密版-毕业设计.zip
毕业论文-Z-BlogPHP海盗导航主题模板-整站商业源码.zip
基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明,该项目是个人毕设项目,答辩评审分达到98分,代码都经过调试测试,确保可以运行!欢迎下载使用,可用于小白学习、进阶。该资源主要针对计算机、通信、人工智能、自动化等相关专业的学生、老师或从业者下载使用,亦可作为期末课程设计、课程大作业、毕业设计等。项目整体具有较高的学习借鉴价值!基础能力强的可以在此基础上修改调整,以实现不同的功能。 基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指挥8种手势识别源码+数据集+模型+详细项目说明基于pytorch实现中国交通警察指
实训商业源码-在线考试系统源码 学生教师用-毕业设计.zip
实训商业源码-自采集壁纸源码小韩美化版-毕业设计.zip
ANSYS nCode DeaignLife 高级疲劳分析技术.pdf
毕业论文-活动报名 4.1.1+年卡 1.1.3-整站商业源码.zip
BIM和PLM技术在市政工程三维设计中的应用.pdf
内容概要:本文档详细介绍了Python反爬虫技术的各种应对策略,包括基础和高级方法。基础部分涵盖User-Agent伪装、IP代理池、请求频率控制等,其中涉及使用fake_useragent库随机生成User-Agent、设置HTTP/HTTPS代理、通过随机延时模拟正常访问行为。动态页面处理方面,讲解了Selenium和Pyppeteer两种自动化工具的使用,可以用于加载并获取JavaScript渲染后的网页内容。对于验证码问题,提供了OCR识别简单验证码、Selenium模拟滑块验证码操作以及利用第三方平台破解复杂验证码的方法。登录态维持章节介绍了如何通过Session对象保持登录状态,并且演示了Cookie的保存与读取。数据加密对抗部分探讨了JavaScript逆向工程和WebAssembly破解技巧,如使用PyExecJS执行解密脚本。最后,高级反爬绕过策略中提到了WebSocket数据抓取和字体反爬解析,确保能够从各种复杂的网络环境中获取所需数据。 适合人群:有一定Python编程经验,从事数据采集工作的开发人员。 使用场景及目标:①帮助开发者理解并掌握多种反爬虫绕过技术;②为实际项目中的数据抓取任务提供有效的解决方案;③提高爬虫程序的成功率和稳定性。 其他说明:在学习过程中,建议结合具体案例进行实践,同时注意遵守网站的robots协议及相关法律法规,合法合规地进行数据采集活动。
毕业论文-叮咚-外卖餐饮小程序6.1.5 前端+后端-整站商业源码.zip
实训商业源码-抢购秒杀系统V1.0.2 安装更新包-毕业设计.zip
实训商业源码-智答-更好用的语音问答6.0.4-毕业设计.zip
毕业论文-发卡-整站商业源码.zip
Ayla NetWorks:全面探索物联网数据安全和数据隐私.pdf
毕业论文-活动报名小程序-整站商业源码.zip
jquery-1.11.0.min.js(jQuery下载)
实训商业源码-易优cms建筑项目施工装饰工程公司网站模板源码-毕业设计.zip
实训商业源码-新麦客服 1.2.8-毕业设计.zip
实训商业源码-在线创建GitHub资源下载链接-毕业设计.zip
实训商业源码-柚子KTV 1.5.9-毕业设计.zip