onclick=quot;location.href=#39;link.html#39;quot; does not load page in Safari(onclick=“location.href=link.html无法在 Safari 中加载页面)
问题描述
我无法让 onclick="location.href='link.html'"
在 Safari (5.0.4) 中加载新页面.
I cannot get onclick="location.href='link.html'"
to load a new page in Safari (5.0.4).
我正在使用 <select>
和 <option>
HTML 标签构建一个下拉导航菜单.我正在使用 onclick
处理程序在单击菜单项后加载新页面,但在 Safari 中没有任何反应.(我已经在 FF & Opera 中成功测试过.)我知道 Safari 中有很多 onclick
错误,但我还没有找到任何解决这个特定问题的解决方案.
I am building a drop-down navigation menu using the <select>
and <option>
HTML tags. I am using the onclick
handler to load a new page after a menu-item is clicked, but nothing happens in Safari. (I have successfully tested in FF & Opera.) I know that there are many onclick
bugs in Safari, but I haven't found any solutions that address this specific issue.
您可以在下面看到我的代码示例:
You can see a sample of my code below:
<select>
<option onclick="location.href='unit_01.htm'">Unit 1</option>
</select>
和
<select>
<option onclick="location.href='#5.2'">Bookmark 2</option>
</select>
我不(也不希望)在我的 HTML 的 head 部分嵌入任何 javascript.我正在为不知道如何使用 javascript 的人开发页面——所以代码越简单越好.)
什么 JavaScript 代码可以使菜单项在所有浏览器中都可点击?(请验证与 IE 的兼容性.)
I do not (and prefer not) to have any javascript embedded in the head section of my HTML. I am developing the page for someone who does not know how to use javascript--so the simpler the code, the better.)
What JavaScript code would make the menu-item clickable in all-browsers? (Please verify compatibility with IE.)
推荐答案
使用 jQuery....我知道你说你想教别人 javascript,但教他更简洁的技术...例如,我可以:
Use jQuery....I know you say you're trying to teach someone javascript, but teach him a cleaner technique... for instance, I could:
<select id="navigation">
<option value="unit_01.htm">Unit 1</option>
<option value="#5.2">Bookmark 2</option>
</select>
加上一点 jQuery,你可以做到:
And with a little jQuery, you could do:
$("#navigation").change(function()
{
document.location.href = $(this).val();
});
不显眼,逻辑和 UI 清晰分离.
Unobtrusive, and with clean separation of logic and UI.
这篇关于onclick=“location.href='link.html'"无法在 Safari 中加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:onclick=“location.href='link.html'"无法在 S


- Fetch API 如何获取响应体? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01