由于某种原因我似乎无法获得我的内容div来调整大小我已经尝试过.css作为替代if语句运行并且可以测试,因为我插入了警报以查看是否if语句导致了这个问题,我完全失去了,并且达到了我的耐心。任何帮助,欢迎提前谢谢。jquery不会改变宽度但是如果语句运行
<!DOCTYPE html>
<html>
<head>
<title>Autofresh</title>
<link rel="stylesheet" type="text/css" href="styles/styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" >
window.onload;
function detectmob() {
if(navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
}
else {
return false;
}
}
if(detectmob()){
window.alert('success');
$("#content").width("100%");
} else {
window.alert('fail');
}
</script>
</head>
<body>
<div id="content" class="mcontent">
<div id="header">
//image goes here
<div id="navbar">
</div>
</div>
<div id="video"></div>
<div id="registration">
</div>
</div>
</body>
</html>
可能是因为不存在的元素,因为页面还没有完全加载(检查控制台错误)。你的'window.onload;'什么都不做。用分配给它的函数括起所有东西。 – Li357
我试过这个,但似乎无法得到它的工作对不起,我是一个新手,当涉及到JavaScript。 –