问题
How would I use this code:
function is_touch_device() {
return !!('ontouchstart' in window) // works on most browsers
|| !!('onmsgesturechange' in window); // works on ie10
};
to detect touch screens and hide a set of divs with the same class.
回答1:
You would simply call the function and use basic logic.
if (is_touch_device()) {
$('.yourclass').hide();
}
回答2:
It would be implemented like this:
window.onload=function(){
if (is_touch_device()){
var divs=document.getElementsByClassName( 'yourclassname');
for (var i=0; i<divs.length; i++)
divs[i].style.display='none';
}
}
function is_touch_device() {
return !!('ontouchstart' in window) // works on most browsers
|| !!('onmsgesturechange' in window); // works on ie10
};
来源:https://stackoverflow.com/questions/14857320/how-would-i-detect-touch-screens-in-jquery-and-hide-a-div