【问题标题】:Why isn't this jQuery script replacing the video declaration with the GIF declaration on an HTML page为什么这个 jQuery 脚本不能用 HTML 页面上的 GIF 声明替换视频声明
【发布时间】:2014-07-22 02:11:44
【问题描述】:

我正在编写一个 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">

我是一个非常初学者的程序员,如果有人能解释一下这里不工作的地方,那将不胜感激!

【问题讨论】:

    标签: javascript jquery html ios user-interface


    【解决方案1】:

    在调用 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">');
    

    我希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 2022-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多