用jquery替换文本

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

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

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

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

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

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

有任何想法吗?

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

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

你可以在这里测试一下

.html()可以接受一个函数,并且不需要在整个过程中创建不必要的jQuery对象(和.html()调用),这将导致大量的CPU周期。

在将数据附加到Google地图之前,您需要执行相同的文本替换。 或者当您将数据附加到谷歌地图时。

我们可能需要查看更多标记以确保选择器正确。 同样,正如Boushley所提到的,时间可能是在jQuery执行后生成(或添加)工具提示。