仅更换替换第一个 [英] Replace only replacing the first

查看:97
本文介绍了仅更换替换第一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码来允许JQuery UI工具提示功能中的换行符。

I am using the following code to allow line breaks in the JQuery UI tooltip function.

$(function() {
    $( document ).tooltip();

    $('.linebreak').tooltip({ 
        content: function(callback) { 
            callback($(this).prop('title').replace('|', '<br />')); 
        }
    });
});

问题是它只能取代 | < br /> 第一次出现,然后离开|适用于其余部分。

The problem is that it only replaces the | to <br /> on the first occurrence and then just leaves the | in place for the rest.

有没有办法替换所有这些,而不仅仅是第一个?

Is there a way to replace all of them, not just the first?

推荐答案

要执行全局替换,您可以使用 g

To perform a global replacement you can use g:

尝试这个

callback($(this).prop('title').replace(/\|/g, '<br />'));

更多infor是 HERE

这篇关于仅更换替换第一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆