的onclick = QUOT; location.href = 'link.html' "不在Safari中加载页面 [英] onclick="location.href='link.html'" does not load page in Safari

查看:132
本文介绍了的onclick = QUOT; location.href = 'link.html' "不在Safari中加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得 onclick =location.href ='link.html'在Safari(5.0.4)中加载新页面。



我使用< select> < option>来构建下拉导航菜单 HTML标签。点击菜单项后,我使用onClick处理程序加载新页面,但Safari中没有任何反应。 (我已经在FF& Opera中成功测试过)。我知道Safari中有很多onClick错误,但是我还没有找到解决这个特定问题的解决方案。



<您可以在下面看到我的代码示例:

 < select> 
< option onclick =location.href ='unit_01.htm'> Unit 1< / option>
< / select>

 <选择> 
< option onclick =location.href ='#5.2'>书签2< / option>
< / select>

我没有(也不喜欢)我的HTML。我正在为不知道如何使用javascript的人开发页面,因此代码越简单越好。)





在所有浏览器中,哪些JavaScript代码可以使菜单项可点击? (请验证与IE的兼容性。)

解决方案

使用jQuery ....我知道你说你想教别人例如,我可以:

 < select id =navigation> ; 
< option value =unit_01.htm> Unit 1< / option>
< option value =#5.2>书签2< / option>
< / select>

使用一个小小的jQuery,你可以这样做:

  $(#navigation)。change(function()
{
document.location.href = $(this).val();
});

不引人注意,并且逻辑和用户界面干净利落。


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.)

解决方案

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>

And with a little jQuery, you could do:

$("#navigation").change(function()
{
    document.location.href = $(this).val();
});

Unobtrusive, and with clean separation of logic and UI.

这篇关于的onclick = QUOT; location.href = 'link.html' &QUOT;不在Safari中加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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