jQuery onclick不工作在移动设备上
16lz
2021-01-22
I'm trying to activate a menu with jQuery with a click (touch) on mobile, but it is not working in mobile. When I do the 'window' resize to try the mobile look, it works with the click, but in an emulator or even trying it with my phone, it doesn't work.
我试着在移动设备上点击(触摸)来激活jQuery菜单,但是它在移动设备上不工作。当我做“窗口”调整大小以尝试移动外观时,它可以通过点击来工作,但在模拟器中,甚至在我的手机中,它都不能工作。
HTML Markup
HTML标记
<img src="i/mobilemenu.jpg" id="mobileMenuButton" style="position:absolute; right:0;"/>
CSS:
CSS:
#mobileNavigation {display:none}
Javascript Code:
Javascript代码:
<script type="text/javascript">
$(document).ready(function(){
$('#mobileMenuButton').on('click touchstart',function(){
if ($('#mobileNavigation').css('display') == 'none') {
$('#mobileNavigation').css('display','block');
}
else
{
$('#mobileNavigation').css('display','none'); }
});
});
</script>
4 个解决方案
#1
0
<script type="text/javascript">
$(document).ready(function(){
$('#mobileMenuButton').on('mousedown touchstart',function(){
var userAgent = window.navigator.userAgent;
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)|| userAgent.match(/Android/i)) {
if ($('#mobileNavigation').css('display') == 'none') {
$('#mobileNavigation').css('display','block');
} else {
$('#mobileNavigation').css('display','none');
}
}
});
});
</script>
Just provide the user agent.
只需提供用户代理。
更多相关文章
- 如何在git特性分支工作流中处理xml/html ?
- 儿童视图不在angular-ui-router中工作
- 为什么ng-hide和ng-show不工作?
- 如何使flex box在safari中工作?
- XSL:包括根本不工作
- 缓存js / css资源以使我的项目脱机工作
- 网页语言有html,php.jsp,无论什么语言浏览器总是能正常显示,这个解
- 不能让align-self在flexbox容器中工作
- 为什么css不能与这个div一起工作?