Home > Web Front-end > JS Tutorial > body text

Detailed introduction to using EL expressions in JS

亚连
Release: 2018-05-17 10:47:13
Original
4200 people have browsed it

There are two situations: 1. The JS code is in the JSP page, which can directly use ELexpression. 2. The JS code is a separate .js file, which is introduced into the JSP. At this time, it can be solved by defining JS variables in advance

1. The JS code is in the JSP page , this can directly use EL expressions. For example:

[html] view plain copy
<script type="text/javascript">  
    $(function () {  
        new BacklogOverview("${param.alert}");  
    });  
</script>
Copy after login

2. The JS code is a separate .js file, which is introduced into the JSP. At this time, it can be solved by defining JS variables in advance, such as :

[html] view plain copy
<c:set var="contextPath" value="${pageContext.request.contextPath}" scope="application"/>  
   <script>  
        <%--JS gloable varilible--%>  
        var contextPath = "${contextPath}";  
    </script>
Copy after login


Define the JS variable contextPath on the JSP page.

So that the contextPath variable can be used in the JS files introduced later.

[html] view plain copy
//Image setting  
config.filebrowserImageUploadUrl = contextPath + "/ckeditor/upload.htm";
Copy after login

The above is I compiled the JS using EL expressions for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Key points analysis and answers to rewriting and polymorphism

How to rewrite the padleft method in js

What are the inheritance methods in js

The above is the detailed content of Detailed introduction to using EL expressions in JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template