在果冻脚本中使用JavaScript



我试图使用在詹金斯JavaScript编写的脚本。我认为最简单的方法是用。jelly脚本调用它们。例如:我有一个文件

myCustom.js :

alert("Hello World!");
function myFunction() {
    var x = "", i;
    for (i=0; i<5; i++) {
        x = x + "The number is " + i + "<br>";
    }
    document.getElementById("demo").innerHTML = x;
}

接下来我有:全球。果冻(来自教程插件):

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
  <f:section title="Hello World Builder">
    <f:entry title="French" field="useFrench"
      description="Check if we should say hello in French">
      <f:checkbox />
      <script type="text/javascript" src="${resURL}/myCustom.js"> 
      </script>
    </f:entry>
  </f:section>
</j:jelly>

问题是:没有效果!甚至Hello World警报也没有显示…我做错了什么?如果我使用:

<script type="text/javascript" >
    alert("Hello World!");
</script>

在果冻,它显示警告窗口,但我不能调用整个文档。也许"${resURL}/myCustom.js"没有正确指向?我应该把我的JS文件放在哪里?

还有一件事:我在Stack上看到过其他问题,但是没有有效的答案,我无法联系到那个问题的所有者。

对于"我应该把我的JS文件放在哪里"的问题,你可以放在src/main/webapp中,在果冻文件中你可以写<script src="${rootURL}/plugin/plugin_name/myCustom.js"/>

把你的脚本放在标签中,并在web-app文件夹中创建一个文件夹js。

最新更新