Javascript 我不知道';我不想显示一个<;部门>;在移动视图中
我用php创建了一个网站,在php主页文件中有一些Javascript 我不知道';我不想显示一个<;部门>;在移动视图中,javascript,php,width,Javascript,Php,Width,我用php创建了一个网站,在php主页文件中有一些标记。这很有效。但我不想在移动视图中显示。我正在尝试学习一些javascript功能,如screen.width,screen.innerWidth,等等。我尝试在javascript中使用screen.width和if…else语句,但仍然不成功。代码应该是什么: 在台式机和笔记本电脑中显示示例,但不在宽度小于500px的设备中显示。主页文件是php格式的,因此建议在其中使用javascript吗?还是首选php?我认为用php很难检测屏幕宽度
标记。这很有效。但我不想在移动视图中显示
。我正在尝试学习一些javascript功能,如screen.width
,screen.innerWidth
,等等。我尝试在javascript中使用screen.width
和if
…else
语句,但仍然不成功。代码应该是什么:
在台式机和笔记本电脑中显示
示例
,但不在宽度小于500px的设备中显示。主页文件是php格式的,因此建议在其中使用javascript吗?还是首选php?我认为用php很难检测屏幕宽度
@media screen and (max-width: 500px) {
#got {
display:none;
}
}
但是你可以很容易地检测到移动设备是否正常工作
为此,请使用以下代码。
<?php
$ua = $_SERVER['HTTP_USER_AGENT']
if (
stristr($ua, "Windows CE") or
stristr($ua, "AvantGo") or
stristr($ua,"Mazingo") or
stristr($ua, "Mobile") or
stristr($ua, "T68") or
stristr($ua,"Syncalot") or
stristr($ua, "Blazer") ) {
$DEVICE_TYPE="MOBILE";
}
if (!(isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE")) {
//put your div to be not shown on mobile devices here.
}
?>
<script type="text/javascript">
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
document.getElementById('got').style.display = "none";
}
</script>
或使用下面的javascript代码。
<?php
$ua = $_SERVER['HTTP_USER_AGENT']
if (
stristr($ua, "Windows CE") or
stristr($ua, "AvantGo") or
stristr($ua,"Mazingo") or
stristr($ua, "Mobile") or
stristr($ua, "T68") or
stristr($ua,"Syncalot") or
stristr($ua, "Blazer") ) {
$DEVICE_TYPE="MOBILE";
}
if (!(isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE")) {
//put your div to be not shown on mobile devices here.
}
?>
<script type="text/javascript">
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
document.getElementById('got').style.display = "none";
}
</script>
if(/Android | webOS | iPhone | iPad | iPod | BlackBerry | IEMobile | Opera Mini/i.test(navigator.userAgent)){
document.getElementById('got').style.display=“无”;
}
或使用下面的css代码
<style type="text/css">
@media only screen and (max-width : 480px) {
#got {
display: none;
}
}
</style>
@仅介质屏幕和(最大宽度:480px){
#得到{
显示:无;
}
}
希望这能帮助你1)发布你当前的代码,2)记住你可以通过css3实现这一点,而无需使用js(搜索媒体查询)。请解释你的答案,使其对其他OP和其他读者更有用。