我相信我正在使用 dojo <1.7
我的JS模块的顶部使用以下声明:
dojo.provide("com.kmbs.portlet.itsform.broadcastemailRequest"(; dojo.require("com.kmbs.portal.core"(;
我一直在寻找有关如何将 html id 和名称属性从 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。
请指教。 谢谢。
编辑:
VerifyUrl 目前在 JSP 中使用 JS 是这样调用的:
<button class="btn" onclick="VerifyUrl()" id="${ns}verifyUrlBtn" disabled>Verify URL</button>
我不知道我是否正确理解了您的问题,但是您可以直接在单击VerifyUrl()
时传递{ns}
值作为参数。因此,您的按钮将如下所示:
<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>