admin管理员组文章数量:1403229
How to do the console.log for EL expression in JS file
jQuery(document).ready(function() {
$('.js-bbCheckbox').click(function(event) {
var bbck = '${tagOne}';
console.log (bbck);
console.log (${tagTwo});
});
How to do the console.log for EL expression in JS file
jQuery(document).ready(function() {
$('.js-bbCheckbox').click(function(event) {
var bbck = '${tagOne}';
console.log (bbck);
console.log (${tagTwo});
});
Share
Improve this question
edited Oct 23, 2012 at 16:04
BalusC
1.1m376 gold badges3.7k silver badges3.6k bronze badges
asked Oct 23, 2012 at 16:00
Shoaib Ud-DinShoaib Ud-Din
4,7343 gold badges26 silver badges23 bronze badges
1
-
Please get your terms right. The
${foo}
is not a "JSTL tag". It's an "EL expression". I edited the question accordingly. In the meanwhile, please carefully read stackoverflow./tags/jstl/info to learn what JSTL really is. – BalusC Commented Oct 23, 2012 at 16:05
2 Answers
Reset to default 5To start, you need to understand that JSP (and JSTL and EL) basically produces HTML (and CSS and JS) code. It doesn't run in sync with JavaScript code. If you rightclick the JSP page in webbrowser and do View Source then you'll see it.
I think that your concrete problem is caused because the ${tagTwo}
returns a plain vanilla string which is in turn by JS been interpreted as a variable name, because it isn't been enclosed in quotes.
You need to let JSP print a fullworthy JS string instead of a variable name.
console.log('${tagTwo}');
@Shoaib Ud-Din, if you don't mind a little inline code, this should work with any included .js file that is loaded after this in the DOM:
<%@ taglib prefix="c" uri="http://java.sun./jstl/core" %>
<c:set var="tagOne" value="Hello World" scope="session" />
<script>
var bbck = "<c:out value="${tagOne}" />";
console.info("<c:out value="${tagOne}" />");
</script>
本文标签: javascriptHow to do the consolelog for EL expression in JS fileStack Overflow
版权声明:本文标题:javascript - How to do the console.log for EL expression in JS file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744308686a2599924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论