onclick=“location.href=”link.html“”无法在 Safari 中加载页面
我无法使用 onclick="location.href='link.html'"
在 Safari (5.0.4) 中加载新页面。
我正在使用
您可以在下面看到我的代码示例:
<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 cannot get onclick="location.href='link.html'"
to load a new page in Safari (5.0.4).
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>
and
<select>
<option onclick="location.href='#5.2'">Bookmark 2</option>
</select>
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个:
在 Firefox、Chrome 和 IE 中运行良好(哇!!)
Try this:
Worked fine for me in Firefox, Chrome and IE (wow!!)
使用 jQuery...我知道你说你想教某人 javascript,但教他一种更干净的技术...例如,我可以:
使用一点 jQuery,你可以做到:
不引人注目,并且干净分离逻辑和UI。
Use jQuery....I know you say you're trying to teach someone javascript, but teach him a cleaner technique... for instance, I could:
And with a little jQuery, you could do:
Unobtrusive, and with clean separation of logic and UI.
试一试:
Give this a go:
您可以尝试以下操作:
这将在链接内创建按钮,并且适用于任何浏览器
You can try this:
This will create button inside a link and it works on any browser
我有同样的错误。确保您没有任何
、
I had the same error. Make sure you don't have any
<input>
,<select>
, etc.name="location"
.尝试
try