我会在这里说得很具体。如果您转到UtahRealEstate.com进行搜索并在地图视图中查看结果,会发现地图上到处都是图,并在右侧列出了列表。如果你点击地图上的一个大头针,你会得到一个弹出窗口,然后点击MLS #,你会得到另一个带有属性描述的弹出窗口。您也可以单击右侧列表上的MLS编号,然后打开属性描述弹出窗口。
我想在弹出窗口的html中添加一个按钮。我可以很好地插入html,但挑战是,我如何确定属性描述何时加载,以便我可以读取其中的html并添加我的按钮?
截图:



发布于 2011-02-05 02:13:17
我使用了一个技巧,即你不会寻找元素,直到你必须基于用户的点击。真正棘手的部分是,地图上卡片上显示的MLS编号链接阻止了点击事件到窗口的传播,因此我无法使用实时点击绑定。
我真的病了,所以我不能再睡太久了,但是代码注释得很好,所以你应该能够读懂我的疯狂。;)
ruleset a60x561 {
meta {
name "utahrealestate"
description <<
utahrealestate
>>
author "Mike Grace"
logging off
}
dispatch {
domain "utahrealestate.com"
}
rule search_for_realestate {
select when web pageview "\/search\/"
pre {
}
{
notify("title","content") with sticky = true;
emit <|
// sidebar click watching easy
// click event isn't being blocked so we can use .live and not
// worry about HTML being present at time of event listener binding
$K(".full_line a").live("click", function() {
console.log("sidebar mls clicked");
// get the report!!!
KOBJ.a60x561.getReport();
});
// pin on map mls number is a bit harder because click event is
// being blocked from propegating to the window
// to get around this we can
// 1) watch for click on pin
// 2) wait for mls element to load
// 3) attatch our own element level event listener
$K("#mapdiv_OpenLayers_Container image").click(function() {
console.log("pin on map clicked");
// attatch click event listener on mls element once it loads
setTimeout(function() {
KOBJ.a60x561.grabMls();
}, 500);
});
// ATATCH LISTENER TO MLS NUM ON MAP
KOBJ.a60x561.grabMls = function() {
console.log("looking for mls in hovercard");
// grab jQuery reference to element we are looking for
var $cardMls = $K("#property-overview a:first");
// only go on if it's on the page and visible
if ( ($cardMls.length > 0) && ($cardMls.is(":visible")) ) {
console.log("foud mls on hevercard");
// watch for click on mls num on card
$cardMls.click(function() {
console.log("mls clicked on hovercard above map pin");
// get the report!!!
KOBJ.a60x561.getReport();
});
} else {
setTimeout(function() {
KOBJ.a60x561.grabMls();
}, 500);
};
};
// GRAB REALESTATE LISTING DETAILS ONCE IT LOADS IN THICK BOX
KOBJ.a60x561.getReport = function() {
if ($K("#public-report-wrap").length > 0) {
console.log("Listing details found!");
} else {
setTimeout(function() {
KOBJ.a60x561.getReport();
}, 500);
};
};
|>;
}
}
}在我测试应用程序时firebug控制台的屏幕截图

发布于 2011-02-04 03:53:32
简短回答(我稍后会进行编辑):
使用操作Watch查看选择器。
然后,使用select when click。
https://stackoverflow.com/questions/4889309
复制相似问题