onclick=“location.href='link.html'"无法在 Safari 中加载页面 [英] onclick="location.href='link.html'" does not load page in Safari

查看:26
本文介绍了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 中加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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