当我响应 Web 事件时,我想让之前操作的(?)通知框消失。是否有 KRL 方法告诉它消失还是必须通过 javascript 完成?
如果必须通过javascript完成,请提供示例
我以前的所有答案都很糟糕!你真正应该做的是触发关闭按钮上的点击事件。
$K(".kGrowl-notification .close").trigger("click");
只需在您响应 Web 事件时发出该 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(".kGrowl", "style", "display:none");
发出[移除](邪恶)
emit <|
$K(".kGrowl").remove();
|>;
发出 [隐藏]
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","");
}
}
}
示例应用程序书签:=> http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-clear-notify-dev_bookmarklet.html
示例应用在 example.com 上运行:
单击清除按钮: