我相信我正在使用dojo <1.7
我的JS模块的顶部使用以下声明:
dojo.provide(“ com.kmbs.portlet.itsform.broadcastemailRequest”);dojo.require(“ com.kmbs.portal.core”);
我一直在寻找有关如何从JSP正确传递html id和name属性到模块的文档。 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>
我不知道我是否正确理解了您的问题,但是您可以在单击{ns}
时直接将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>