我看过这里,大多数人说它的逃避问题所以我认为我也是错的。我看谷歌,大多数都有一个div的文本替换另一个div的例子。这里我想用.js中的if语句替换默认内容“mainMidSec”
我正在尝试为移动网站测试一些东西......但是我遇到了语法错误。我几乎肯定它与引号等有关...我已经尝试了外部双内部单引号,反之亦然,它没有接受它。
以下是代码:
<script type="text/javascript">
var screenW = document.getElementById('mainMidSec');
if ((screen.width<=800) && (screen.height<=800))
{
screenW.innerHTML = '<video width="500" height="400" controls poster="imgs/vidPosterImgSMALLER.jpg">
<source src="videos/mp4-video-versions/2010reel_MP4.mp4">
<p> Your current web browser is out of date . Please update it wont you...pretty please?</p>
</video>'
}
</script>
你们贬低我的任何想法/建议/知识炸弹我都会高兴而谦卑地接受!
答案 0 :(得分:5)
您不能将字符串拆分为多行。
将字符串放在一行:
screenW.innerHTML = '<video width="500" height="400" controls poster="imgs/vidPosterImgSMALLER.jpg"><source src="videos/mp4-video-versions/2010reel_MP4.mp4"><p> Your current web browser is out of date . Please update it wont you...pretty please?</p></video>';
或者将每一行作为单独的字符串:
screenW.innerHTML = '<video width="500" height="400" controls poster="imgs/vidPosterImgSMALLER.jpg">' +
'<source src="videos/mp4-video-versions/2010reel_MP4.mp4">' +
'<p> Your current web browser is out of date . Please update it wont you...pretty please?</p>' +
'</video>';
答案 1 :(得分:2)
在javascript中,你不能在字符串中包含换行符。尝试:
screenW.innerHTML = '<video width="500" height="400" controls poster="imgs/vidPosterImgSMALLER.jpg"><source src="videos/mp4-video-versions/2010reel_MP4.mp4"> <p> Your current web browser is out of date . Please update it wont you...pretty please?</p></video>'
另外,请查看CSS Media Queries,这是处理移动设备备用布局的推荐方法。
答案 2 :(得分:1)
变化:
screenW.innerHTML = '<video width="500" height="400" controls poster="imgs/vidPosterImgSMALLER.jpg">
<source src="videos/mp4-video-versions/2010reel_MP4.mp4">
<p> Your current web browser is out of date . Please update it wont you...pretty please?</p>
致:
screenW.innerHTML = '<video width="500" height="400" controls poster="imgs/vidPosterImgSMALLER.jpg"> ' +
'<source src="videos/mp4-video-versions/2010reel_MP4.mp4"> ' +
'<p> Your current web browser is out of date . Please update it wont you...pretty please?</p> ' +
''