1

我相信我正在使用 dojo < 1.7

我的 JS 模块的顶部使用了这些声明:

dojo.provide("com.kmbs.portlet.itsform.broadcastemailRequest"); dojo.require("com.kmbs.portal.core");

我一直在搜索有关如何将 html id 和 name 属性从 JSP 传递给模块的文档。JSP 上有一个表单,并且有几个输入字段可以根据用户输入动态(通过 JS)更改。

例子:

我有这个html:

<input id="${ns}verifyurlflag" type="hidden" name="verifyurlflag" value="0">

我想在模块中使用这个 JS(需要将其转换为模块格式,我知道。)

function VerifyUrl() {
    var emailUrl = document.getElementById("${ns}emailUrl").value;
    if(emailUrl){
        // Set to True (1)
        $('#${ns}verifyurlflag').val("1");
        window.open( emailUrl, '_blank', 'toolbar=no,scrollbars=yes,menubar=yes,location=no,resizable=yes,height=500,width=700,top=100');
    }
}

其中 ${ns} 是用于自动命名空间前缀的 JSTL。

请指教。谢谢你。

编辑:

目前在 JSP 中使用 JS 调用 VerifyUrl 是这样的:

<button class="btn" onclick="VerifyUrl()" id="${ns}verifyUrlBtn" disabled>Verify URL</button>

4

1 回答 1

0

我不知道我是否正确理解了您的问题,但是您可以{ns}直接将 onclick 的值VerifyUrl()作为参数传递。因此,您的按钮如下所示:

<button class="btn" onclick="VerifyUrl('${ns}')" id="${ns}verifyUrlBtn" disabled>Verify URL</button>

演示代码

//value parameter passed in function will have ${ns} value
function VerifyUrl(value) {
  var emailUrl = document.getElementById(value + "emailUrl").value;
  if (emailUrl != null) {
    // Set to True (1) 
    $('#' + value + 'verifyurlflag').val("1");
    window.open(emailUrl, '_blank', 'toolbar=no,scrollbars=yes,menubar=yes,location=no,resizable=yes,height=500,width=700,top=100');
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="aemailUrl" type="text" name="emailUrl" value="https://www.google.com/">
<input id="averifyurlflag" type="text" name="verifyurlflag" value="0">
<!--pass in function ${ns} i.e : VerifyUrl('${ns}')-->
<button class="btn" onclick="VerifyUrl('a')" id="${ns}verifyUrlBtn">Verify URL</button>

于 2020-05-16T04:23:54.240 回答