作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个 jQuery 脚本来检测访问我网站的用户何时在 iOS 设备上,以及何时将网站背景从视频切换为 GIF,因为 .mp4 和 .webm 文件iOS 版本的 Safari 不支持。该脚本使用 modernizr.js 和 uisearch.js 作为支持文件。该脚本直接包含在 HTML 中,而不是作为单独的文件。在这里:
$(document).ready(function() {
if((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/iPad/i))) {
('.video-background').remove();
('body').prepend('<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">');
}
});
它试图更改的 HTML 如下所示:
<body div="main" class="html front not-logged-in no-sidebars page-node page-node- page-node-16 node-type-panel role-1 lightbox-processed">
<div class="video-background">
<video id="video" preload="none" poster="./index_files" autoplay="autoplay" loop="true">
<source src="./index_files/Test_cut_soundless_WEBM.webm" type="video/webm">
<source src="./index_files/Test_cut_soundless_MP4.mp4" type="video/mp4">
</video>
</div>
它正在尝试将其更改为:
<body div="main" class="html front not-logged-in no-sidebars page-node page-node- page-node-16 node-type-panel role-1 lightbox-processed">
<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">
我是一个非常初级的程序员,如果有人可以阐明这里不起作用的地方,那将不胜感激!
最佳答案
在调用 remove 和 prepend 时,您在开头缺少 $
这里:
('.video-background').remove();
('body').prepend('<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">');
将其替换为:
$('.video-background').remove();
$('body').prepend('<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">');
希望对您有所帮助:)
关于javascript - 为什么这个 jQuery 脚本没有用 HTML 页面上的 GIF 声明替换视频声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23986411/
我是一名优秀的程序员,十分优秀!