所以我使用 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 函数,它使用第三部分工具提示,div 是“simple_example_window”,其中包含所有 html。我尝试在 offon 函数中使用 simple_example_window 作为 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 = '<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}
);
它就像一个魅力。现在唯一的问题是我在谷歌地图中的工具提示没有改变。
有什么想法吗?
最佳答案
我从评论中看到您发现了这一点,这里只是一个优化版本:
function offon(){
$("#sidebar li").html(function(i, h){
return h.replace(/Off Premise/, "Liquor Store")
.replace(/On Premise/, "Bar/Restaurant");
});
}
.html()
可以接受一个函数,并且不需要一路创建不必要的 jQuery 对象(和 .html()
调用),这将导致节省大量的 CPU 周期。
关于javascript - 文本替换为jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3197195/