Opera 10,jquery 与正则表达式替换

发布于 2024-08-14 09:12:02 字数 573 浏览 2 评论 0原文

我有一个适用于除 Opera 之外的所有浏览器的 jquery 插件。触发了removeHighlight函数,但html没有改变。据我所知,IE、FF、Chrome 和 Safari 都按预期工作。

我的例子可以在这里找到: http://www.pritaeas.net/public/jquery/plugin-dev/< /a>

插件的 url 是: http://www.pritaeas.net/public/jquery/ plugin-dev/jquery.highlight.js

基本上,我只想删除具有特定类的所有 span 标签,保留文本不变。

谁能解释为什么 Opera 的反应不同,并提供解决方案或解决方法?

谢谢。

I have a jquery plugin that is working on all browsers, except opera. The removeHighlight function gets triggered, but the html is not changed. As far as I can see IE, FF, Chrome and Safari work as expected.

My example can be found here:
http://www.pritaeas.net/public/jquery/plugin-dev/

The plugin's url is:
http://www.pritaeas.net/public/jquery/plugin-dev/jquery.highlight.js

Basically, I just want to remove all span tags with a specific class, leaving the text as-is.

Can anyone explain why opera is responding differently, and provide a solution or work-around ?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老子叫无熙 2024-08-21 09:12:02

问题出在正则表达式中的 removeHighlight 函数中。我不知道为什么,但如果你的正则表达式是形式的,它就不起作用:

var source = new RegExp("<span class=.?" + options["cssClass"] + ".?>(.*?)</span>", "ig");

尤其是第一个 .? 在这种情况下是有问题的。当您将其更改为 .\" 时,您的正则表达式效果很好。您可以使用 \" 形式,就像格式正确的 html all 一样属性应该用括号括起来,你也可以将它们添加到 highlight 函数中:

var target = "<span class=\"" + options["cssClass"] + "\">%&</span>";

Problem is in your removeHighlight function, in regex. I don't know why, but your regex doesn't work if it is in form:

var source = new RegExp("<span class=.?" + options["cssClass"] + ".?>(.*?)</span>", "ig");

especially first .? is problematic in this case. When you change it to . or \", then your regex works great. You can use \" form, as in correctly formatted html all attributes should be enclosed in parenthesis, and you can add them in highlight function too:

var target = "<span class=\"" + options["cssClass"] + "\">%&</span>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文