[英]How to update a JSP page html element using ceratin Javascript logic?
I have a JSP page called root.jsp
, in that i have a footer tag which displaces certain text( that is coming from a properties file from java end). 我有一个名为root.jsp
的JSP页面,其中有一个页脚标记,用于替换某些文本(来自Java端的属性文件)。 The footer tag itself is displayed using scriplets based on certain roles that is logged in to the Site. 基于登录到站点的某些角色,使用脚本显示了页脚标签本身。 root.jsp
has global.js
file included here is the code snippet root.jsp
包含global.js
文件,这里是代码片段
**root.jsp**
<%if(role.equals("Learner")){%>
<footer>
<p id ="par1">${userAccessMsg}.</p>
<p id ="par2">${userNoFolderAccessMsg}.</p>
</footer>
<%} %>
I need to display only one <p>
tag by checking if the variable folders
is empty or not . 通过检查变量folders
是否为空,我只需要显示一个<p>
标记。
**global.js**
var folders = getConfigLinkedFolders();
function getConfigLinkedFolders {
return arrayList; /*["defssfsf","hrhrhhr"] */
}
How should i do this? 我应该怎么做?
Have a method in the DOM ready handler where in you can add a class to the element in question. 在DOM ready处理程序中有一个方法,您可以在其中将一个类添加到有问题的元素中。
$(document).ready(function() {
var folders = getConfigLinkedFolders();
if(folders && folders.length > 0) {
$('#par2').addClass('hide');
} else {
$('#par1').addClass('hide');
}
});
function getConfigLinkedFolders {
return arrayList; /*["defssfsf","hrhrhhr"] */
}
And in your CSS file define the class hide
并在您的CSS文件中定义类hide
.hide {
display : none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.