【发布时间】:2015-04-27 07:04:37
【问题描述】:
我正在尝试根据用户在页面上显示不同的可能链接。例如,不允许移动用户向我们的数据库提交数据。我找到了一个检测移动用户的 Javascript 函数,但我无法获得它的输出来指示向用户显示的链接。事实上,当我尝试使用以下代码时,根本没有显示任何链接。
</head>
<body>
</div>
<div id="topcontent">
<p align="center">
<div id="banner">
<p align="center">
<script>
function checkMobile(){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
<a href="studyAreas.html">
Wifi Study Areas</a>
<a href="displayspeeds.html">
View all Speeds</a>
<a href="bestlocation.html">
Best Speed Near You</a>
<a href="squadfree/index.html">
About Us</a>
}
else{
<a href="studyAreas.html">
Wifi Study Areas</a>
<a href="displayspeeds.html">
View all Speeds</a>
<a href="bestlocation.html">
Best Speed Near You</a>
<a href="userEnterInfo.html">
Add Speed Data</a>
<a href="squadfree/index.html">
About Us</a>
}
}
</script>
</p>
</div>
<div id="centercontent">
<h3 align="center">
Find the best study space</h3>
<h1 align="center">
Check Your Internet Speed With WiFly</h1>
<p align="center">
<img src="http://cdn.flaticon.com/png/256/15402.png" alt="wifi" />
</p>
<p align="center">
</p>
</div>
</body>
【问题讨论】:
-
好吧,你不能只在你的 javascript 函数中编写 html 代码。例如,您可以淡入正确的 html 部分,或者用代码填充必要的元素(设置 innerhtml)
-
@Fank Provost 说的是真的,最重要的是你为什么要在段落标签中添加 div 标签?
标签: javascript html