当我回复网络活动时,我想让之前有效的(?)通知框消失。是否有KRL方式告诉它消失或者是否必须通过javascript完成?
如果必须通过javascript完成,请提供示例
答案 0 :(得分:3)
我之前的所有答案都很糟糕!你真正应该做的是触发关闭按钮上的点击事件。
$K(".kGrowl-notification .close").trigger("click");
在您回复网络活动时,只需发出JavaScript即可。
更好的示例应用
ruleset a60x469 {
meta {
name "better-close-notify-example"
description <<
better-close-notify-example
>>
author "Mike Grace"
logging on
}
rule put_notify_on_page {
select when pageview ".*"
{
// put notify on page
notify("Hello","I'm on your page") with sticky = true;
// raise web event
emit <|
setTimeout(function() {
app = KOBJ.get_application("a60x469");
app.raise_event("clear_notify");
}, 2000);
|>;
}
}
rule clear_notify {
select when web clear_notify
{
emit <|
$K(".kGrowl-notification .close").trigger("click")
|>;
}
}
}
有几种方法可以实现这一目标。
<强>示例:强>
set_element_attr
set_element_attr(".kGrowl", "style", "display:none");
发出[删除](邪恶)
emit <|
$K(".kGrowl").remove();
|>;
发出[hide]
emit <|
$K(".kGrowl").hide();
|>;
replace_html(邪恶)
replace_html(".kGrowl","");
完整的应用示例:
ruleset a60x468 {
meta {
name "example-clear-notify"
description <<
example-clear-notify
>>
author "Mike Grace"
logging on
}
rule put_notify_on_page {
select when pageview ".*"
pre {
button =<<
<button id="clear-notify">Click me to clear the notify</button>
>>;
}
{
notify("Hello","I'm on your page") with sticky = true;
append("body", button);
emit <|
$K("#clear-notify").click(function() {
app = KOBJ.get_application("a60x468");
app.raise_event("clear_notify");
});
|>;
}
}
rule clear_notify {
select when web clear_notify
{
replace_inner(".kGrowl","");
}
}
}
示例应用书签:=&gt; http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-clear-notify-dev_bookmarklet.html
示例应用在example.com上运行:
点击清除按钮: