草庐IT

jQuery 和 iOS 设备

coder 2024-01-17 原文

我有 html 格式的纯文本。我将类添加到某些标签以使用 jQuery 即时格式化它们。

在 PC 和 Android 上一切正常,但在 iOS 上没有任何反应。可能是什么错误?

示例代码如下

<script>
var $=jQuery.noConflict();
jQuery( document ).ready(function() { 
    var dialog = $( "p:has(strong)" ).addClass( "wi-dialog" );
    var chapter = $( "p:has(ins)" ).addClass( "wi-chapter" );
    dialog.html(function(i, v) { return v.replace(/(?<=\n)\s*(\(.*?\)).*?/g, '<span class="wi-remark">$&</span>') });

    var more = $(".wi-remark:contains(MORE)").addClass( "wi-more").removeClass( "wi-remark");

    var p = $('p:not(.wi-dialog,.wi-chapter)');
    p.filter(function() { 
        return ((/^[0-9.]+$/).test($(this).html())); 
    }).addClass("wi-number");
    p.filter(function() {
        return ((/^(THE END)+$/).test($(this).html())); }).addClass( "wi-end" );
    });
});
</script>

问题就在这里

dialog.html(function(i, v) { return v.replace(/(?<=\n)\s*(\(.*?\)).*?/g, '<span class="wi-remark">$&</span>') });

文本示例

<p><strong>HENRY</strong>
Gather more wood.</p>

<p>Fitzgerald waits for Henry to turn, then gives his back an exaggerated salute.</p>

<p><strong>FITZGERALD</strong><br>
(under his breath)<br>
Shame my Pap was a broken down drunk. Else he could’ve bought me a Captain’s job too.</p>

<p>Boone snickers. Fitzgerald stomps his boot onto a branch, easily snaps it into two easy-to-carry pieces.</p>

<p><strong>FITZGERALD</strong> (CONT’D)<br>
We got a plan for these fires, Captain, or are we roastin’ berries all the way up to Fort Union?</p>

<p><strong>HENRY</strong><br>
Glass and the others will be back with some game, Fitzgerald. Just make sure you have the fires ready.</p>

<p><strong>FITZGERALD</strong><br>
My supper’s in the hands of a injun- lover, a peach-fuzz kid and a half- wit dummy. Hell, my belly feels full already.</p>

最佳答案

此解决方案应该适合您。问题是负面回顾,它在某些 iOS 版本上不起作用。现在它改用非捕获组。

$(document).ready(function(){
  var dialog = $( "p:has(strong)" ).addClass( "wi-dialog" )
  for (var i = 0; i < dialog.length; i++) {
    e = dialog.eq(i)
    var e_html = e.html()
    var pattern = /(?:\n)\s*(\(.*?\)).*?/gm
    var match = pattern.exec(e_html)
    while (match != null) {
      e_html = e_html.replace(match[1], '<span class="wi-remark">$&</span>')
      match = pattern.exec(e_html)
    }
    e.html(e_html)
  }
})
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
  </head>
  <body>
    <p>
      <strong>FITZGERALD</strong> (CONT’D)<br>
      Shut up, boy, you don’t get no say in this.<br>
      (back to Henry)<br>
      And in case you hadn’t noticed, Captain, we’re seventeen men short of what we were.
      (off the wounded trapper)<br>
      Eighteen before long.
    </p>
    <p>
      <strong>FITZGERALD</strong><br>
      (under his breath)<br>
      Shame my Pap was a broken down drunk. Else he could’ve bought me a Captain’s job too.
    </p>
  </body>
</html>

关于jQuery 和 iOS 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57728760/

有关jQuery 和 iOS 设备的更多相关文章

  1. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  2. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  3. jquery - 我的 jquery AJAX POST 请求无需发送 Authenticity Token (Rails) - 2

    rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送

  4. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  5. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  6. jquery - 如何将 AJAX 变量从 jQuery 传递到他们的 Controller ? - 2

    我有一个电子邮件表格。但是我正在制作一个测试电子邮件表单,用户可以在其中添加一个唯一的电子邮件,并让电子邮件测试将其发送到该特定电子邮件。为了简单起见,我决定让测试电子邮件通过ajax执行,并将整个内容粘贴到另一个电子邮件表单中。我不知道如何将变量从我的HAML发送到我的Controllernew.html.haml-form_tagadmin_email_blast_pathdoSubject%br=text_field_tag'subject',:class=>"mass_email_subject"%brBody%br=text_area_tag'message','',:nam

  7. ruby-on-rails - 禁用设备的 :confirmable on-the-fly to batch-generate users - 2

    Devise是一个Ruby库,它为我提供了这个User类:classUser当写入:confirmable时,注册时会发送一封确认邮件。上周我不得不批量创建300个用户,所以我在恢复之前注释掉了:confirmable几分钟。现在我正在为用户批量创建创建一个UI,因此我需要即时添加/删除:confirmable。(我也可以直接修改Devise的源码,但我宁愿不去调和它)问题:如何即时添加/删除:confirmable? 最佳答案 WayneConrad的解决方案:user=User.newuser.skip_confirmation

  8. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  9. jquery - 如何在 rails 3.1 上安装 jQuery - 2

    我以为它已经安装了,但在我的gemfile中有gem"jquery-rails"但是在我的asset/javascripts文件夹中accounts.js.coffeeapplication.js都被注释掉了这是我的虚拟railsapplication但是在源代码中没有jQuery并且删除链接不起作用......任何想法都丢失了 最佳答案 看看thisRailscast.您可能需要检查application.js文件并确保它包含以下语句。//=requirejquery//=requirejquery_ujs

  10. jquery - Rails 如何创建 Jquery flash 消息而不是默认的 Rails 消息 - 2

    我想在页面顶部创建自定义Jquery消息而不是标准RailsFlash消息。我想在我的投票底部附近创建一条即时消息。我的Controller:defvote_up@post=Post.find(params[:id])current_user.up_vote(@post)flash[:message]='Thanksforvoting!'redirect_to(root_path,:notice=>'Takforditindlæg,deternuonline!')rescueMakeVoteable::Exceptions::AlreadyVotedErrorflash[:error]

随机推荐