我正在编写一个应用程序来尝试和修改使用JavaScript的页面,我无法弄清楚我要运行的JavaScript的放置位置。我正在使用$ K的KRL特定jQuery句柄。
- 我可以在我的KRL规则集/应用程序中使用JavaScript的所有地方在哪里?
- 你有没有一个例子演示在这些方面使用JavaScript?
我正在编写一个应用程序来尝试和修改使用JavaScript的页面,我无法弄清楚我要运行的JavaScript的放置位置。我正在使用$ K的KRL特定jQuery句柄。
有两种方法可以将JavaScript直接放到KRL规则集的网页中。通过发射块或外部资源。我们先讨论发射块。
发出可以出现在规则的动作块或规则集的全局块中。您可以使用heredoc或clownhats排放,但小丑是首选。
下面是一个规则发出的JavaScript的例子:
rule emitter {
select when web pageview "exampley.com"
{
emit <|
$K("body").append("Hello from a rule.");
|>;
}
}
下面是一个全球性的块发出的JavaScript的例子:
global {
emit <|
$K("body").append("Hello from the global block.");
|>;
}
放置的JavaScript在KRL页面上的第二种方法是使用external resource。
我会向您推荐的具体链接的文档,但你有一个外部的JavaScript资源在您的规则集的元块,像这样:
use javascript resource "url-to-resource"
比方说,我有以下的位于JavaScript文件在my-personal-website.com/awesome.js
内容:
$K("body").append("Hello from an external resource.");
要使用的规则集:
meta {
// normal meta stuff...
use javascript resource "my-personal-website.com/awesome.js"
}
这里展示两种不同的方式来放置JavaScript的网页上的KRL规则集一个完整的规则集:在exampley.com运行的应用程序后,
ruleset a369x151 {
meta {
name "fun-with-javascript"
description <<
fun-with-javascript
>>
author "AKO"
logging on
use javascript resource "http://dl.dropbox.com/u/4917848/js/example-external-resource.js"
}
global {
emit <|
$K("body").append("<br/>Hello from the global block.");
|>;
}
rule emitter {
select when web pageview "exampley.com"
{
emit <|
$K("body").append("<br/>Hello from a rule.");
|>;
}
}
}
动作射击:
你可以自己尝试一下获取应用程序书签here。
哇,这个问题看起来很熟悉! :) – Dustin 2011-02-03 17:06:18