问题描述
jQuery的单击事件似乎并没有被解雇的移动浏览器。
the jQuery click event does not seem to be firing in mobile browsers.
的HTML是如下:
<!-- This is the main menu -->
<ul class="menu">
<li><a href="/home/">HOME</a></li>
<li class="publications">PUBLICATIONS & PROJECTS</li>
<li><a href="/about/">ABOUT</a></li>
<li><a href="/blog/">BLOG</a></li>
<li><a href="/contact/">CONTACT</a></li>
</ul>
<!-- This is the sub-menu that is to be fired on click -->
<div id="filter_wrapper">
<ul id="portfolioFilter">
<li><a href="/nutrition-related/">Nutrition related</a></li>
<li><a href="/essays/">Essays and Nonfiction</a></li>
<li><a href="/commissioned/">Commissioned works</a></li>
<li><a href="/plays/">Plays and performance</a></li>
<li><a href="/new-projects/">New Projects</a></li>
</ul>
</div>
这是jQuery脚本移动:
This is the jQuery script for mobile:
$(document).ready(function(){
$('.publications').click(function() {
$('#filter_wrapper').show();
});
});
当我点击一个移动浏览器没有任何反应出版物列表项。
When I click the "publications" list item on a mobile browser nothing happens.
您可以在这里查看网站: http://www.ruthcrocker.com/
You can view the site here: http://www.ruthcrocker.com/
不知道是否有jQuery Mobile的具体事件。
Not sure if there are jQuery mobile specific events.
推荐答案
Raminson具有使用jQuery Mobile的,如果你已经(或不介意)一个很好的答案。如果你想要一个不同的解决方案,为什么不修改code如下:
Raminson has a nice answer if you are already (or don't mind) using jQuery Mobile. If you want a different solution, why not just modify your code as follows:
更改,李您遇到麻烦,包括一个标签,并应用LI
change that LI you're having trouble with to include an A tag and apply the class there instead of the LI
<!-- This is the main menu -->
<ul class="menu">
<li><a href="/home/">HOME</a></li>
<li><a href="#" class="publications">PUBLICATIONS & PROJECTS</a></li>
<li><a href="/about/">ABOUT</a></li>
<li><a href="/blog/">BLOG</a></li>
<li><a href="/contact/">CONTACT</a></li>
</ul>
和你的JavaScript / jQuery的code ...返回false停止冒泡。
And your javascript/jquery code... return false to stop bubbling.
$(document).ready(function(){
$('.publications').click(function() {
$('#filter_wrapper').show();
return false;
});
});
这应该为你工作正在努力做的事情。
This should work for what you are trying to do.
另外,我注意到你的网站打开新的标签页/窗口中的各个环节,是故意的吗?
Also, I noticed your site opens the other links in new tabs/windows, is that intentional?
这篇关于jQuery的单击事件不工作在移动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!