用jquery替换文本 [英] text replace with jquery

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

问题描述

所以我使用jquery来搜索和替换我的html页面中的某些文本。这是:

So im using jquery to search and replace certain text in my html page. Which is:

function offon(){
  $("#sidebar li").each(function(){
     $(this).html($(this).html().replace(/Off Premise/, "Liquor Store"));
     $(this).html($(this).html().replace(/On Premise/, "Bar/Restaurant"));
  });
}

这是创建标记功能,它使用第3部分工具提示div是 simple_example_window包含所有html。我尝试使用simple_example_window作为offon函数中的div,但它没有做任何事情。

This is the createmarker function, it uses a 3rd part tooltip the div is "simple_example_window" that contains all the html. I tried using simple_example_window for the div in the offon function but it did not do anything.

http://gmaps-utility-library-dev.googlecode.com/svn/trunk/extinfowindow/docs/examples.html
是该插件。

http://gmaps-utility-library-dev.googlecode.com/svn/trunk/extinfowindow/docs/examples.html is the plugin.

function createMarker(point, name, address, type) {
var marker = new GMarker(point, customIcons[type]);
  markerGroups[type].push(marker);
var html = '<span class="name"><b>' + name + '</b></span> <br/>' + address + '<br/>' +     type;
GEvent.addListener(marker, 'click', function() {
    marker.openExtInfoWindow(
      map,
      "simple_example_window",
     html,
      {beakOffset: 2}
    );

它就像一个魅力。现在唯一的问题我的谷歌地图中的工具提示没有变化。

It works like a charm. The only problem now is my tooltips in google maps are not changing.

任何想法?

推荐答案

我从评论中看到你想出来的,这里只是一些优化版本:

I see from the comments you figured this out, just a bit of an optimized version here:

function offon(){
  $("#sidebar li").html(function(i, h){
     return h.replace(/Off Premise/, "Liquor Store")
             .replace(/On Premise/, "Bar/Restaurant");
  });
}

您可以在此测试

< a href =http://api.jquery.com/html/ =nofollow noreferrer> .html() 可以使用一个函数,而且不需要创造你不必要的jQuery对象(和 .html() 很多的CPU周期。

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

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